Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. struct AllocTable_t
  2. {
  3.     bool IsAllocated;
  4.     uint8_t AllocByCoreId;
  5.     uint8_t AllocByTaskId;
  6.     uint8_t Reserve1;
  7. };
  8.  
  9. class PoolAlloc
  10. {
  11. private:
  12.     // A define
  13.     const uint32_t InvalidChunkIndex = ULONG_MAX;
  14.     // Number of total blocks available at the start
  15.     uint32_t NumberOfChunks;
  16.     // Debug
  17.     AllocTable_t *AllocationTablePtr;
  18.     // Start offset of the dynamic memory region
  19.     uint32_t *StartPtr;
  20.     // Size of allocation memory block, bytes
  21.     uint32_t ChunkSize;
  22.     // Offset to chunk zero
  23.     uint32_t *Chunks;
  24.     uint32_t *FreeChunksList;
  25.     int32_t FreeChunkIndex;
  26.     // Init
  27.     void InitChunksTable(uint32_t TableSize);
  28.     // Mark chunk at index N as allocated
  29.     uint32_t * AllocateChunkInternal(uint32_t ChunkNumber);
  30.     // Mark chunk at index N as free on the de-allocation
  31.     void DeAllocateChunkInternal(uint32_t ChunkNumber);
  32.     // Get chunk num
  33.     uint32_t CalculateChunkNumFromPtr(void *Ptr);
  34.     // Get first free chunk
  35.     uint32_t GetFreeChunkID(void);
  36.  
  37.     PoolAlloc();
  38.  
  39. public:
  40.  
  41.     // -> rename to Initialize
  42.     PoolAlloc(void *StartMemAddr, void *FinishMemAddr, uint32_t ChunkSize_in);
  43.  
  44.     //
  45.     uint32_t * AllocateChunk();
  46.    
  47.     void DeAllocateChunk(void *ChunkPtr);
  48.     uint32_t GetChunkSize(void) const;
  49.     void ShowStatistics();
  50. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement