Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <stdlib.h>
00011 #include "c++.h"
00012 #include "WProgram.h"
00013
00014 void * operator new(size_t size)
00015 {
00016 #ifdef AP_DISPLAYMEM
00017 displayMemory();
00018 #endif
00019 return(calloc(size, 1));
00020 }
00021
00022 void operator delete(void *p)
00023 {
00024 if (p) free(p);
00025 }
00026
00027 #if 0
00028
00029
00030 extern "C" void __cxa_pure_virtual()
00031 {
00032 while (1);
00033 }
00034 #endif
00035
00036 void * operator new[](size_t size)
00037 {
00038 #ifdef AP_DISPLAYMEM
00039 displayMemory();
00040 #endif
00041 return(calloc(size, 1));
00042 }
00043
00044 void operator delete[](void * ptr)
00045 {
00046 if (ptr) free(ptr);
00047 }
00048
00049 __extension__ typedef int __guard __attribute__((mode (__DI__)));
00050
00051 int __cxa_guard_acquire(__guard *g)
00052 {
00053 return !*(char *)(g);
00054 };
00055
00056 void __cxa_guard_release (__guard *g)
00057 {
00058 *(char *)g = 1;
00059 };
00060
00061 void __cxa_guard_abort (__guard *) {};
00062
00063
00064 extern unsigned int __bss_end;
00065 extern void *__brkval;
00066
00067 void displayMemory()
00068 {
00069 static int minMemFree=0;
00070 if (minMemFree<=0 || freeMemory()<minMemFree) {
00071 minMemFree = freeMemory();
00072 Serial.print("bytes free: ");
00073 Serial.println(minMemFree);
00074 }
00075 }
00076
00077 int freeMemory()
00078 {
00079 int free_memory;
00080
00081 if ((int)__brkval == 0)
00082 free_memory = ((int)&free_memory) - ((int)&__bss_end);
00083 else
00084 free_memory = ((int)&free_memory) - ((int)__brkval);
00085
00086 return free_memory;
00087 }