operator.cpp 469 B

12345678910111213141516171819202122
  1. #include <memory>
  2. #include <esp_heap_caps.h>
  3. void* operator new(std::size_t count) {
  4. return heap_caps_malloc(count, MALLOC_CAP_SPIRAM);
  5. }
  6. void operator delete(void* ptr) noexcept {
  7. if (ptr) free(ptr);
  8. }
  9. /*
  10. // C++17 only
  11. void* operator new (std::size_t count, std::align_val_t alignment) {
  12. return heap_caps_malloc(count, MALLOC_CAP_SPIRAM);
  13. }
  14. // C++17 only
  15. void operator delete(void* ptr, std::align_val_t alignment) noexcept {
  16. if (ptr) free(ptr);
  17. }
  18. */