-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage_allocator.h
More file actions
43 lines (37 loc) · 955 Bytes
/
page_allocator.h
File metadata and controls
43 lines (37 loc) · 955 Bytes
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
#pragma once
#include "memory_pool.h"
struct PageAllocator : public MemoryPool
{
PageAllocator( size_t pageSize )
: allocated( 0 )
, data( nullptr )
{
data = new unsigned char[ pageSize ];
if ( data )
{
capacity = pageSize;
}
}
~PageAllocator()
{
delete [] data;
}
void* allocate( size_t size ) override
{
void* result = nullptr;
if ( ( capacity - allocated ) > size )
{
result = data + allocated;
allocated += size;
}
return result;
}
void free( void* allocation ) override
{
assert( allocation >= data && allocation < ( data + capacity ) ); // Check not deleting from the wrong pool, not expecting to delete allocations from here
}
private:
size_t allocated;
size_t capacity;
unsigned char* data;
};