2010-10-17 01:02:06 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*-
|
|
|
|
|
|
|
|
//
|
|
|
|
// C++ runtime support not provided by Arduino
|
|
|
|
//
|
|
|
|
// Note: use new/delete with caution. The heap is small and
|
|
|
|
// easily fragmented.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2010-12-23 19:02:51 -04:00
|
|
|
#include "c++.h"
|
|
|
|
#include "WProgram.h"
|
2010-10-17 01:02:06 -03:00
|
|
|
|
2010-12-28 19:33:27 -04:00
|
|
|
void * operator new(size_t size)
|
2010-10-17 01:02:06 -03:00
|
|
|
{
|
2010-12-30 01:25:28 -04:00
|
|
|
#ifdef AP_DISPLAYMEM
|
|
|
|
displayMemory();
|
|
|
|
#endif
|
2010-10-17 01:02:06 -03:00
|
|
|
return(calloc(size, 1));
|
|
|
|
}
|
|
|
|
|
2010-12-28 19:33:27 -04:00
|
|
|
void operator delete(void *p)
|
2010-10-17 01:02:06 -03:00
|
|
|
{
|
2010-12-23 19:02:51 -04:00
|
|
|
if (p) free(p);
|
|
|
|
}
|
|
|
|
|
2010-12-28 19:33:27 -04:00
|
|
|
extern "C" void __cxa_pure_virtual()
|
2010-12-28 19:29:46 -04:00
|
|
|
{
|
2010-12-31 02:20:28 -04:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
Serial.println("Error: pure virtual call");
|
|
|
|
delay(1000);
|
|
|
|
}
|
2010-12-28 19:29:46 -04:00
|
|
|
}
|
|
|
|
|
2010-12-23 19:02:51 -04:00
|
|
|
void * operator new[](size_t size)
|
|
|
|
{
|
2010-12-30 01:25:28 -04:00
|
|
|
#ifdef AP_DISPLAYMEM
|
|
|
|
displayMemory();
|
|
|
|
#endif
|
2010-12-28 19:29:46 -04:00
|
|
|
return(calloc(size, 1));
|
2010-12-23 19:02:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void operator delete[](void * ptr)
|
|
|
|
{
|
|
|
|
if (ptr) free(ptr);
|
2010-10-17 01:02:06 -03:00
|
|
|
}
|
2010-11-18 13:52:41 -04:00
|
|
|
|
|
|
|
__extension__ typedef int __guard __attribute__((mode (__DI__)));
|
|
|
|
|
2010-12-28 19:33:27 -04:00
|
|
|
int __cxa_guard_acquire(__guard *g)
|
2010-11-18 13:52:41 -04:00
|
|
|
{
|
|
|
|
return !*(char *)(g);
|
|
|
|
};
|
|
|
|
|
2010-12-28 19:33:27 -04:00
|
|
|
void __cxa_guard_release (__guard *g)
|
2010-11-18 13:52:41 -04:00
|
|
|
{
|
|
|
|
*(char *)g = 1;
|
|
|
|
};
|
|
|
|
|
2010-12-28 19:33:27 -04:00
|
|
|
void __cxa_guard_abort (__guard *) {};
|
2010-12-23 19:02:51 -04:00
|
|
|
|
|
|
|
// free memory
|
|
|
|
extern unsigned int __bss_end;
|
|
|
|
extern void *__brkval;
|
|
|
|
|
|
|
|
void displayMemory()
|
|
|
|
{
|
|
|
|
static int minMemFree=0;
|
|
|
|
if (minMemFree<=0 || freeMemory()<minMemFree) {
|
|
|
|
minMemFree = freeMemory();
|
|
|
|
Serial.print("bytes free: ");
|
|
|
|
Serial.println(minMemFree);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int freeMemory()
|
|
|
|
{
|
|
|
|
int free_memory;
|
|
|
|
|
2011-10-07 19:15:36 -03:00
|
|
|
if ((intptr_t)__brkval == 0)
|
|
|
|
free_memory = ((intptr_t)&free_memory) - ((intptr_t)&__bss_end);
|
2010-12-23 19:02:51 -04:00
|
|
|
else
|
2011-10-07 19:15:36 -03:00
|
|
|
free_memory = ((intptr_t)&free_memory) - ((intptr_t)__brkval);
|
2010-12-23 19:02:51 -04:00
|
|
|
|
|
|
|
return free_memory;
|
|
|
|
}
|