4#include "AudioToolsConfig.h"
5#include "AudioTools/CoreAudio/AudioLogger.h"
6#include "AudioTools/CoreAudio/AudioRuntime.h"
30 T* ref =
new (addr) T();
37 if (obj ==
nullptr)
return;
44 T* createArray(
int len) {
45 void* addr =
allocate(
sizeof(T) * len);
48#ifndef NO_INPLACE_INIT_SUPPORT
49 for (
int j = 0; j < len; j++)
new (addrT + j) T();
52 for (
int j = 0; j < len; j++) {
53 memcpy((uint8_t*)addr+(j*
sizeof(T)), &default_value,
sizeof(T));
61 void removeArray(T* obj,
int len) {
62 if (obj ==
nullptr)
return;
63 for (
int j = 0; j < len; j++) {
71 void* result = do_allocate(size);
72 if (result ==
nullptr) {
73 LOGE(
"Allocateation failed for %zu bytes", size);
76 LOGD(
"Allocated %zu", size);
82 virtual void free(
void* memory) {
83 if (memory !=
nullptr)
::free(memory);
82 virtual void free(
void* memory) {
…}
87 virtual void* do_allocate(
size_t size) {
88 return calloc(1, size == 0 ? 1 : size);
100 void* do_allocate(
size_t size) {
101 void* result =
nullptr;
102 if (size == 0) size = 1;
103#if (defined(RP2040) || defined(ESP32)) && defined(ARDUINO)
104 result = ps_malloc(size);
106 if (result ==
nullptr) result = malloc(size);
107 if (result ==
nullptr) {
108 LOGE(
"allocateation failed for %zu bytes", size);
112 memset(result, 0, size);
118#if (defined(ESP32)) && defined(ARDUINO)
128 class AllocatorESP32 :
public Allocator {
129 AllocatorESP32(
int caps = MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL) {
132 void* do_allocate(
size_t size) {
133 void* result =
nullptr;
134 if (size == 0) size = 1;
135 result = heap_caps_calloc(1, size, caps);
136 if (result ==
nullptr) {
137 LOGE(
"alloc failed for %zu bytes", size);
149#if (defined(RP2040) || defined(ESP32)) && defined(ARDUINO)
159class AllocatorPSRAM :
public Allocator {
160 void* do_allocate(
size_t size) {
161 if (size == 0) size = 1;
162 void* result =
nullptr;
163 result = ps_calloc(1, size);
164 if (result ==
nullptr) {
165 LOGE(
"allocateation failed for %zu bytes", size);
174static AllocatorExt DefaultAllocator;
void stop()
Public generic methods.
Definition AudioRuntime.h:14