blob: d505ab3ef4e3245244bdfec71ec329d88cfefd0c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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);
}
|