#include "platform/esp/arduino_common/memory/psram_allocator.h" #include "platform/memory/psram_allocator.h" #include #include #include #include #include int main() { using Allocator = platform::memory::PsramAllocator; static_assert(std::is_same_v>); { std::vector bytes(64); assert(bytes.size() == 64 && allocations == 1 && allocation_caps == (MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT)); } assert(deallocations == 1); fail_allocation = true; bool refused = false; try { std::vector bytes(64); } catch (const std::bad_alloc&) { refused = true; } assert(refused && deallocations == 1); // No fallback to the internal heap. platform::memory::PsramAllocator wide; refused = false; const auto before = allocations; try { (void)wide.allocate(std::numeric_limits::max()); } catch (const std::bad_alloc&) { refused = true; } assert(refused && allocations == before); }