Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" // blinky starts with mbed lib 76, however this was updated to lib 81 00002 #include "Utility.h" 00003 //#include "RawSerial.h" 00004 00005 Serial pc(USBTX, USBRX); 00006 DigitalOut myled(LED1); 00007 extern "C" void mbed_reset(); 00008 00009 void* operator new(size_t size) throw() 00010 { 00011 void *ptr; 00012 00013 ptr = malloc(size); 00014 return ptr; 00015 } 00016 00017 void operator delete(void *ptr) throw() 00018 { 00019 free(ptr); 00020 } 00021 00022 void operator delete[](void *ptr) throw() 00023 { 00024 free(ptr); 00025 } 00026 00027 int main() { 00028 //pc.baud(460800); // I like a snappy terminal, so crank it up! 00029 int f = Free(); 00030 pc.printf("\r\nBlinky eating memory - Build " __DATE__ " " __TIME__ "\r\n"); 00031 pc.printf(" %d bytes free\r\n", f); 00032 int i = 2000; 00033 int total = 0; 00034 00035 while(1) { 00036 myled = 1; 00037 wait(0.2); 00038 pc.printf("Allocating %d bytes in addition to %d already allocated.\r\n", i, total); 00039 char * p = new char [i]; // This never returns after 24000 00040 //char * p = (char *)malloc(i); // This fails gracefully with NULL return after 24000 00041 pc.printf(" %d bytes free.\r\n", Free()); 00042 __heapvalid((__heapprt)fprintf, stdout, 0); 00043 if (p) { 00044 total += i; 00045 pc.printf(" Success! \r\n"); 00046 } else { 00047 pc.printf(" Failed...\r\n"); 00048 break; 00049 } 00050 myled = 0; 00051 wait(0.2); 00052 } 00053 pc.printf("done.\r\n"); 00054 while (!pc.readable()) {} 00055 mbed_reset(); 00056 }
Generated on Wed Jul 27 2022 02:03:25 by
 1.7.2
 1.7.2