66class GeneralMemoryAllocator {
68 GeneralMemoryAllocator();
69 [[gnu::always_inline]]
void* allocMaxSpeed(uint32_t requiredSize,
void* thingNotToStealFrom =
nullptr) {
70 return alloc(requiredSize,
true,
false, thingNotToStealFrom);
73 [[gnu::always_inline]]
void* allocLowSpeed(uint32_t requiredSize,
void* thingNotToStealFrom =
nullptr) {
74 return alloc(requiredSize,
false,
false, thingNotToStealFrom);
80 template <std::derived_from<Stealable> T>
81 [[gnu::always_inline]]
void*
allocStealable(uint32_t requiredSize =
sizeof(T),
82 void* thingNotToStealFrom =
nullptr) {
83 return alloc(requiredSize,
false,
true, thingNotToStealFrom);
86 void* alloc(uint32_t requiredSize,
bool mayUseOnChipRam,
bool makeStealable,
void* thingNotToStealFrom);
87 void dealloc(
void* address);
88 void* allocExternal(uint32_t requiredSize);
89 void* allocInternal(uint32_t requiredSize);
90 void deallocExternal(
void* address);
91 uint32_t shortenRight(
void* address, uint32_t newSize);
92 uint32_t shortenLeft(
void* address, uint32_t amountToShorten, uint32_t numBytesToMoveRightIfSuccessful = 0);
93 void extend(
void* address, uint32_t minAmountToExtend, uint32_t idealAmountToExtend,
94 uint32_t* getAmountExtendedLeft, uint32_t* getAmountExtendedRight,
void* thingNotToStealFrom =
nullptr);
95 uint32_t extendRightAsMuchAsEasilyPossible(
void* address);
97 uint32_t getAllocatedSize(
void* address);
98 void checkStack(
char const* caller);
99 void testShorten(int32_t i);
100 int32_t getRegion(
void* address);
101 void testMemoryDeallocated(
void* address);
103 void putStealableInQueue(
Stealable* stealable, StealableQueue q);
104 void putStealableInAppropriateQueue(
Stealable* stealable);
110 uint32_t stealableSectionsEnd = 0;
115 static GeneralMemoryAllocator& get() {
116 static GeneralMemoryAllocator generalMemoryAllocator;
117 return generalMemoryAllocator;
121 void checkEverythingOk(
char const* errorString);