FastLED 3.9.15
Loading...
Searching...
No Matches
memory_resource.h
Go to the documentation of this file.
1#pragma once
2
7
8#include "fl/stl/int.h"
9#include "fl/stl/noexcept.h"
10
11namespace fl {
12
17 public:
18 virtual ~memory_resource() FL_NOEXCEPT = default;
19
20 void* allocate(fl::size bytes) FL_NOEXCEPT {
21 if (bytes == 0) return nullptr;
22 return do_allocate(bytes);
23 }
24
25 void deallocate(void* p, fl::size bytes) FL_NOEXCEPT {
26 if (!p) return;
27 do_deallocate(p, bytes);
28 }
29
32 void* reallocate(void* p, fl::size old_bytes, fl::size new_bytes) FL_NOEXCEPT {
33 if (new_bytes == 0) {
34 deallocate(p, old_bytes);
35 return nullptr;
36 }
37 if (!p) return allocate(new_bytes);
38 return do_reallocate(p, old_bytes, new_bytes);
39 }
40
41 bool is_equal(const memory_resource& other) const FL_NOEXCEPT {
42 return do_is_equal(other);
43 }
44
45 protected:
46 virtual void* do_allocate(fl::size bytes) FL_NOEXCEPT = 0;
47 virtual void do_deallocate(void* p, fl::size bytes) FL_NOEXCEPT = 0;
48
50 virtual void* do_reallocate(void* p, fl::size old_bytes, fl::size new_bytes) FL_NOEXCEPT;
51
52 virtual bool do_is_equal(const memory_resource& other) const FL_NOEXCEPT {
53 return this == &other;
54 }
55};
56
58memory_resource* default_memory_resource() FL_NOEXCEPT;
59
61memory_resource* psram_memory_resource() FL_NOEXCEPT;
62
63} // namespace fl
void deallocate(void *p, fl::size bytes) FL_NOEXCEPT
virtual void * do_reallocate(void *p, fl::size old_bytes, fl::size new_bytes) FL_NOEXCEPT
Default: returns nullptr (not supported). Override for realloc-capable resources.
void * allocate(fl::size bytes) FL_NOEXCEPT
virtual void do_deallocate(void *p, fl::size bytes) FL_NOEXCEPT=0
virtual void * do_allocate(fl::size bytes) FL_NOEXCEPT=0
bool is_equal(const memory_resource &other) const FL_NOEXCEPT
virtual ~memory_resource() FL_NOEXCEPT=default
virtual bool do_is_equal(const memory_resource &other) const FL_NOEXCEPT
void * reallocate(void *p, fl::size old_bytes, fl::size new_bytes) FL_NOEXCEPT
Try to resize in-place.
Polymorphic memory resource base class (PMR-style).
memory_resource * default_memory_resource() FL_NOEXCEPT
Get the default memory resource (wraps fl::Malloc / fl::Free / fl::realloc).
memory_resource * psram_memory_resource()
Get the PSRAM memory resource (wraps PSRamAllocate / PSRamDeallocate).
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT