ardupilot/libraries/AP_Common/c++.cpp

41 lines
733 B
C++
Raw Normal View History

2013-05-29 20:52:38 -03:00
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
//
// C++ runtime support not provided by Arduino
//
// Note: use new/delete with caution. The heap is small and
// easily fragmented.
#include <AP_HAL/AP_HAL.h>
#include <stdlib.h>
/*
globally override new and delete to ensure that we always start with
zero memory. This ensures consistent behaviour.
*/
void * operator new(size_t size)
{
if (size < 1) {
size = 1;
}
2011-10-28 15:43:43 -03:00
return(calloc(size, 1));
}
void operator delete(void *p)
{
2011-10-28 15:43:43 -03:00
if (p) free(p);
}
void * operator new[](size_t size)
{
if (size < 1) {
size = 1;
}
return(calloc(size, 1));
}
void operator delete[](void * ptr)
{
if (ptr) free(ptr);
}