c++.cpp 655 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. //
  2. // C++ runtime support not provided by Arduino
  3. //
  4. // Note: use new/delete with caution. The heap is small and
  5. // easily fragmented.
  6. #include <AP_HAL/AP_HAL.h>
  7. #include <stdlib.h>
  8. /*
  9. globally override new and delete to ensure that we always start with
  10. zero memory. This ensures consistent behaviour.
  11. */
  12. void * operator new(size_t size)
  13. {
  14. if (size < 1) {
  15. size = 1;
  16. }
  17. return(calloc(size, 1));
  18. }
  19. void operator delete(void *p)
  20. {
  21. if (p) free(p);
  22. }
  23. void * operator new[](size_t size)
  24. {
  25. if (size < 1) {
  26. size = 1;
  27. }
  28. return(calloc(size, 1));
  29. }
  30. void operator delete[](void * ptr)
  31. {
  32. if (ptr) free(ptr);
  33. }