Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct AllocTable_t
- {
- bool IsAllocated;
- uint8_t AllocByCoreId;
- uint8_t AllocByTaskId;
- uint8_t Reserve1;
- };
- class PoolAlloc
- {
- private:
- // A define
- const uint32_t InvalidChunkIndex = ULONG_MAX;
- // Number of total blocks available at the start
- uint32_t NumberOfChunks;
- // Debug
- AllocTable_t *AllocationTablePtr;
- // Start offset of the dynamic memory region
- uint32_t *StartPtr;
- // Size of allocation memory block, bytes
- uint32_t ChunkSize;
- // Offset to chunk zero
- uint32_t *Chunks;
- uint32_t *FreeChunksList;
- int32_t FreeChunkIndex;
- // Init
- void InitChunksTable(uint32_t TableSize);
- // Mark chunk at index N as allocated
- uint32_t * AllocateChunkInternal(uint32_t ChunkNumber);
- // Mark chunk at index N as free on the de-allocation
- void DeAllocateChunkInternal(uint32_t ChunkNumber);
- // Get chunk num
- uint32_t CalculateChunkNumFromPtr(void *Ptr);
- // Get first free chunk
- uint32_t GetFreeChunkID(void);
- PoolAlloc();
- public:
- // -> rename to Initialize
- PoolAlloc(void *StartMemAddr, void *FinishMemAddr, uint32_t ChunkSize_in);
- //
- uint32_t * AllocateChunk();
- void DeAllocateChunk(void *ChunkPtr);
- uint32_t GetChunkSize(void) const;
- void ShowStatistics();
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement