1#ifndef _MEMORY_ALLOCATOR_H_
2#define _MEMORY_ALLOCATOR_H_
13#include <basictypes.h>
24 virtual void *allocate(
size_t size) = 0;
25 virtual void deallocate(
void *ptr) = 0;
26 virtual void *reallocate(
void *ptr,
size_t size) = 0;
27 virtual ~MemoryAllocator() {}
30class BlockMemoryAllocator :
public MemoryAllocator
33 BlockMemoryAllocator(
void *pMemory,
size_t memorySize,
size_t blockSize);
34 ~BlockMemoryAllocator()
override;
35 void *allocate(
size_t size)
override;
36 void deallocate(
void *ptr)
override;
37 void *reallocate(
void *ptr,
size_t size)
override;
39 void printStats()
const;
51 size_t _blockSizeMultiplier;
53 const size_t largestSizeToAllocate = 10560;
56 size_t _numAllocations;
57 size_t _numDeallocations;
58 size_t _numOOMAllocations;
59 size_t _numToLargeAllocations;
60 size_t _allocatedMemory;
62 size_t getBlockSize(Block *pBlock)
const;
63 size_t getAlignedBlockSize(
size_t size)
const;
64 Block *getBlockFromPointer(
void *pBlock)
const;
65 void splitBlock(Block *pBlock,
size_t size);
66 void coalesceBlocks(Block *pBlock);
70#define CREATE_MEMORY_ALLOCATOR_SRAM(name, memorySize) \
71 alignas(4) static uint8_t memoryBuffer##name[memorySize] FAST_USER_VAR; \
72 BlockMemoryAllocator name(memoryBuffer##name, memorySize, 32)
74#define CREATE_MEMORY_ALLOCATOR_TCM(name, memorySize) \
75 alignas(4) static uint8_t memoryBuffer##name[memorySize] FAST_SYS_VAR; \
76 BlockMemoryAllocator name(memoryBuffer##name, memorySize, 32)
78#define CREATE_MEMORY_ALLOCATOR_SDRAM(name, memorySize) \
79 alignas(4) static uint8_t memoryBuffer##name[memorySize]; \
80 BlockMemoryAllocator name(memoryBuffer##name, memorySize, 32)
NetBurner System Constants.
NetBurner Real-Time Operating System (NBRTOS) API.
An OS_CRIT object is used to establish critical sections of code that can only be run by one task at ...
Definition nbrtos.h:1110