AP_Common c++ lib: eliminate freeMemory and displayMemory

* also, no more error message in pure virtual call
This commit is contained in:
Pat Hickey 2012-10-26 20:02:59 -07:00 committed by Andrew Tridgell
parent 9f9c183a4d
commit f58935d1e7
2 changed files with 3 additions and 59 deletions

View File

@ -11,19 +11,8 @@
#include <stdint.h>
#include "c++.h"
#ifndef EXCLUDECORE
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#endif
void * operator new(size_t size)
{
#ifdef AP_DISPLAYMEM
displayMemory();
#endif
return(calloc(size, 1));
}
@ -32,22 +21,12 @@ void operator delete(void *p)
if (p) free(p);
}
extern "C" void __cxa_pure_virtual()
{
while (1)
{
#ifndef EXCLUDECORE
Serial.println("Error: pure virtual call");
delay(1000);
#endif
}
extern "C" void __cxa_pure_virtual(){
while (1){}
}
void * operator new[](size_t size)
{
#ifdef AP_DISPLAYMEM
displayMemory();
#endif
return(calloc(size, 1));
}
@ -63,38 +42,10 @@ int __cxa_guard_acquire(__guard *g)
return !*(char *)(g);
};
void __cxa_guard_release (__guard *g)
{
void __cxa_guard_release (__guard *g){
*(char *)g = 1;
};
void __cxa_guard_abort (__guard *) {
};
// free memory
extern unsigned int __bss_end;
extern void *__brkval;
void displayMemory()
{
static int minMemFree=0;
if (minMemFree<=0 || freeMemory()<minMemFree) {
minMemFree = freeMemory();
#ifndef EXCLUDECORE
Serial.print("bytes free: ");
Serial.println(minMemFree);
#endif
}
}
int freeMemory()
{
int free_memory;
if ((intptr_t)__brkval == 0)
free_memory = ((intptr_t)&free_memory) - ((intptr_t)&__bss_end);
else
free_memory = ((intptr_t)&free_memory) - ((intptr_t)__brkval);
return free_memory;
}

View File

@ -1,7 +0,0 @@
#ifndef CPP_H
#define CPP_H
void displayMemory();
int freeMemory();
#endif