Force large c++ arrays into PSRAM

This is mostly targetted at leveldb_ which is rude and does not support
custom allocators
This commit is contained in:
jacqueline
2023-09-26 10:18:33 +10:00
parent a87790a424
commit 2849399d54
2 changed files with 30 additions and 0 deletions
+1
View File
@@ -3,5 +3,6 @@
# SPDX-License-Identifier: GPL-3.0-only # SPDX-License-Identifier: GPL-3.0-only
idf_component_register( idf_component_register(
SRCS "allocator.cpp"
INCLUDE_DIRS "include" INCLUDE_DIRS "include"
REQUIRES "database") REQUIRES "database")
+29
View File
@@ -0,0 +1,29 @@
/*
* Copyright 2023 jacqueline <me@jacqueline.id.au>
*
* SPDX-License-Identifier: GPL-3.0-only
*/
#include <cstdint>
#include "esp_heap_caps.h"
void* operator new[](std::size_t sz) {
if (sz == 0) {
++sz; // avoid std::malloc(0) which may return nullptr on success
}
if (sz > 256) {
return heap_caps_malloc(sz, MALLOC_CAP_SPIRAM);
}
return heap_caps_malloc(sz, MALLOC_CAP_DEFAULT);
}
void operator delete[](void* ptr) noexcept {
heap_caps_free(ptr);
}
void operator delete[](void* ptr, std::size_t size) noexcept {
heap_caps_free(ptr);
}