A pager using a linear allocation algorithm. More...
Public Member Functions | |
LinearPager (unsigned long long pageSize, UniquePtr< MemorySpaceAllocator< U >> allocator=makeUnique< DefaultMemorySpaceAllocator< U >>()) noexcept | |
unsigned long long | getPageSize () const |
unsigned long long | getCurrentOffset () const |
unsigned long long | getAllocatedPageCount () const |
unsigned long long | getAvailablePageCount () const |
T | allocate (unsigned long long size, unsigned long long alignment=1) |
void | reset () |
unsigned long long | getCurrentPageFreeMemory () const |
A pager using a linear allocation algorithm.
A linear pager will allocate sequentially in the active page. When the page is full, a new page is allocated. Resetting the pager resets all allocations. This kind of pager can be useful in scenarios where allocations are used for a purpose and can be fred right after.
For instance, in a 3d renderer, it can be used to page resources used on a per frame basis (allocate for the frame, reset, reuse allocations for next frame).
|
noexcept |
Constructor.
pageSize | The size wanted for pages within the pager, in number of elements. |
allocator | The memory space allocator, allowing to customize how the pages are allocated. |
unsigned long long nkMemory::LinearPager< T, U >::getPageSize | ( | ) | const |
unsigned long long nkMemory::LinearPager< T, U >::getCurrentOffset | ( | ) | const |
unsigned long long nkMemory::LinearPager< T, U >::getAllocatedPageCount | ( | ) | const |
unsigned long long nkMemory::LinearPager< T, U >::getAvailablePageCount | ( | ) | const |
T nkMemory::LinearPager< T, U >::allocate | ( | unsigned long long | size, |
unsigned long long | alignment = 1 |
||
) |
Requests an allocation.
size | The size needed for the allocation, in number of elements. |
alignment | The alignment needed for the allocation. |
void nkMemory::LinearPager< T, U >::reset | ( | ) |
Resets the status of the pager. This will make the pager reset its current tracking within the pages. Note that no memory will be freed. The point is to make already allocated memory usable again.
unsigned long long nkMemory::LinearPager< T, U >::getCurrentPageFreeMemory | ( | ) | const |