Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
cppMemory.cpp
Go to the documentation of this file.
1
16 #include "pico/stdlib.h"
17 #include <cstring>
18 #include "FreeRTOS.h"
19 #include <stdio.h>
20
21 #ifndef UNIT_TEST
22
23 void* operator new(size_t size) {
24 void* pData = pvPortMalloc(size);
25 if (!pData) {
26 printf("ERROR: Memory allocation failed for size %zu!\n", size);
27 while(1); // Trap in infinite loop to catch memory failures
28 }
29 memset(pData, 0, size);
30 return pData;
31 }
32
33 void* operator new[](size_t size) {
34 return pvPortMalloc(size);
35 }
36
37 void operator delete(void* ptr) {
38 if (ptr) {
39 vPortFree(ptr);
40 }
41 }
42
43 void operator delete[](void* ptr) {
44 if (ptr) {
45 vPortFree(ptr);
46 }
47 }
48
49 // Placement new — required for STL
50 void* operator new(size_t, void* ptr) noexcept {
51 return ptr;
52 }
53
54 void* operator new[](size_t, void* ptr) noexcept {
55 return ptr;
56 }
57
58 #endif
59