Lugdunum  0.1.0
Chunk.inl
Go to the documentation of this file.
1 template <size_t MaxSize, size_t MaxAlignment, size_t Offset>
3 
4 template <size_t MaxSize, size_t MaxAlignment, size_t Offset>
5 void* Chunk<MaxSize, MaxAlignment, Offset>::allocate(size_t size, size_t alignment, size_t offset) {
6  LUG_ASSERT(offset == Offset, "Chunk allocator doesn't support multiple offset");
7  LUG_ASSERT(MaxSize >= size, "Size of the allocation is greater than the chunk's max size");
8  LUG_ASSERT(MaxAlignment >= alignment, "Alignment of the allocation is greater than the chunk's max alignment");
9 
10  void* const ptr = _freeList.allocate();
11 
12  if (ptr) {
13  return ptr;
14  }
15 
16  if (!_currentPage || !_freeList.grow(_currentPage->start, _currentPage->end, MaxAlignment, Offset)) {
17  return nullptr;
18  }
19 
21  return allocate(size, alignment, offset);
22 }
23 
24 template <size_t MaxSize, size_t MaxAlignment, size_t Offset>
26  _freeList.free(ptr);
27 }
28 
29 template <size_t MaxSize, size_t MaxAlignment, size_t Offset>
31  _freeList.reset();
33 }
34 
35 template <size_t MaxSize, size_t MaxAlignment, size_t Offset>
38 }
size_t getSize(void *ptr) const
Definition: Chunk.inl:36
#define LUG_ASSERT(assertion, message)
Definition: Debug.hpp:38
virtual Page * requestNextPage()=0
lug::System::Memory::Area::Page * _firstPage
Definition: Chunk.hpp:58
void * allocate(size_t size, size_t alignment, size_t offset)
Definition: Chunk.inl:5
lug::System::Memory::Area::Page * _currentPage
Definition: Chunk.hpp:57
bool grow(void *start, void *end, size_t alignment, size_t offset)
Definition: FreeList.cpp:13
lug::System::Memory::Area::IArea *const _area
Definition: Chunk.hpp:54