FastLED 3.9.3
Loading...
Searching...
No Matches
allocator.h
1
2#pragma once
3
4#include <stddef.h>
5#include <string.h>
6
7#include "namespace.h"
8
9
10FASTLED_NAMESPACE_BEGIN
11
12void SetLargeBlockAllocator(void *(*alloc)(size_t), void (*free)(void *));
13void* LargeBlockAllocate(size_t size, bool zero = true);
14void LargeBlockDeallocate(void* ptr);
15
16template<typename T>
18public:
19 static T* Alloc(size_t n) {
20 void* ptr = LargeBlockAllocate(sizeof(T) * n, true);
21 return reinterpret_cast<T*>(ptr);
22 }
23
24 static void Free(T* p, size_t n) {
25 (void)n;
26 if (p == nullptr) {
27 return;
28 }
29 LargeBlockDeallocate(p);
30 }
31};
32
33FASTLED_NAMESPACE_END