-
Notifications
You must be signed in to change notification settings - Fork 0
/
heap_alloc.h
47 lines (37 loc) · 979 Bytes
/
heap_alloc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#include <stdint.h>
namespace Memory
{
struct free_block
{
free_block* Next;
int32_t Size;
};
struct allocation_info
{
uint8_t* Base;
int32_t Size;
uint8_t AlignmentOffset;
};
struct heap_allocator
{
uint8_t* m_Base;
int32_t m_Capacity;
uint8_t* m_Barrier;
free_block* m_FirstFreeBlock;
allocation_info* m_AllocInfos;
int32_t m_AllocCount;
public:
void Create(void* Base, int32_t Capacity);
uint8_t* Alloc(int32_t SizeBytes);
uint8_t* AllignedAlloc(int32_t SizeBytes, int32_t Alignment);
void Dealloc(uint8_t* Start);
void Clear();
uint8_t* GetBase() const;
int32_t GetTotalUsedSize() const;
int32_t GetInternalFragmentation() const;
int32_t GetAllocationCount() const;
allocation_info* GetAllocationInfos() const;
};
heap_allocator* CreateHeapAllocatorInPlace(void* Base, int32_t Capacity);
}