1
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
43
44
45
46
47
55
63
64
72
73
76
83
84
91
/* ... */
#include <cstdlib>
#include "esp_heap_caps.h"
#pragma once
/* ... */
struct ExceptionlessAllocatable {
/* ... */
static void *operator new( std::size_t ) = delete;
static void *operator new[]( std::size_t ) = delete;
/* ... */
void *operator new (size_t size, const std::nothrow_t&) noexcept {
#ifdef CONFIG_NVS_ALLOCATE_CACHE_IN_SPIRAM
return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT | MALLOC_CAP_SPIRAM,
MALLOC_CAP_DEFAULT | MALLOC_CAP_INTERNAL);/* ... */
#else
return std::malloc(size);
#endif
}{...}
void *operator new [](size_t size, const std::nothrow_t&) noexcept {
#ifdef CONFIG_NVS_ALLOCATE_CACHE_IN_SPIRAM
return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT | MALLOC_CAP_SPIRAM,
MALLOC_CAP_DEFAULT | MALLOC_CAP_INTERNAL);/* ... */
#else
return std::malloc(size);
#endif
}{...}
/* ... */
void operator delete (void *obj) noexcept {
#ifdef CONFIG_NVS_ALLOCATE_CACHE_IN_SPIRAM
return heap_caps_free(obj);
#else
return std::free(obj);
#endif
}{...}
void operator delete [](void *obj) noexcept {
#ifdef CONFIG_NVS_ALLOCATE_CACHE_IN_SPIRAM
return heap_caps_free(obj);
#else
return std::free(obj);
#endif
}{...}
}{ ... };