mirror of
https://github.com/meshtastic/firmware.git
synced 2025-02-11 23:21:25 +00:00
34 lines
933 B
C
34 lines
933 B
C
![]() |
#pragma once
|
||
|
#include <Arduino.h>
|
||
|
|
||
|
#define POOL_SIZE 32768
|
||
|
|
||
|
/**
|
||
|
* An allocator (and placement new operator) that allocates storage from a fixed sized buffer.
|
||
|
* It will panic if that buffer fills up.
|
||
|
* If you are _sure_ no outstanding references to blocks in this buffer still exist, you can call
|
||
|
* reset() to start from scratch.
|
||
|
*
|
||
|
* Currently the only usecase for this class is the ESP32 bluetooth stack, where once we've called deinit(false)
|
||
|
* we are sure all those bluetooth objects no longer exist, and we'll need to recreate them when we restart bluetooth
|
||
|
*/
|
||
|
class SimpleAllocator
|
||
|
{
|
||
|
uint8_t bytes[POOL_SIZE];
|
||
|
|
||
|
uint32_t nextFree;
|
||
|
|
||
|
public:
|
||
|
SimpleAllocator();
|
||
|
|
||
|
void *alloc(size_t size);
|
||
|
|
||
|
/** If you are _sure_ no outstanding references to blocks in this buffer still exist, you can call
|
||
|
* reset() to start from scratch.
|
||
|
* */
|
||
|
void reset();
|
||
|
};
|
||
|
|
||
|
void *operator new(size_t size, SimpleAllocator &p);
|
||
|
|