API Documentation
Public Member Functions | List of all members
nkMemory::LinearPager< T, U > Class Template Referencefinal

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
 
allocate (unsigned long long size, unsigned long long alignment=1)
 
void reset ()
 
unsigned long long getCurrentPageFreeMemory () const
 

Detailed Description

template<typename T = char*, typename U = DefaultMemorySpace>
class nkMemory::LinearPager< T, U >

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).

Constructor & Destructor Documentation

◆ LinearPager()

template<typename T = char*, typename U = DefaultMemorySpace>
nkMemory::LinearPager< T, U >::LinearPager ( unsigned long long  pageSize,
UniquePtr< MemorySpaceAllocator< U >>  allocator = makeUnique< DefaultMemorySpaceAllocator< U >>() 
)
noexcept

Constructor.

Parameters
pageSizeThe size wanted for pages within the pager, in number of elements.
allocatorThe memory space allocator, allowing to customize how the pages are allocated.

Member Function Documentation

◆ getPageSize()

template<typename T = char*, typename U = DefaultMemorySpace>
unsigned long long nkMemory::LinearPager< T, U >::getPageSize ( ) const
Returns
The page size used in the pager.

◆ getCurrentOffset()

template<typename T = char*, typename U = DefaultMemorySpace>
unsigned long long nkMemory::LinearPager< T, U >::getCurrentOffset ( ) const
Returns
The current offset within the active page.

◆ getAllocatedPageCount()

template<typename T = char*, typename U = DefaultMemorySpace>
unsigned long long nkMemory::LinearPager< T, U >::getAllocatedPageCount ( ) const
Returns
The number of pages currently allocated.

◆ getAvailablePageCount()

template<typename T = char*, typename U = DefaultMemorySpace>
unsigned long long nkMemory::LinearPager< T, U >::getAvailablePageCount ( ) const
Returns
The number of pages still available.

◆ allocate()

template<typename T = char*, typename U = DefaultMemorySpace>
T nkMemory::LinearPager< T, U >::allocate ( unsigned long long  size,
unsigned long long  alignment = 1 
)

Requests an allocation.

Parameters
sizeThe size needed for the allocation, in number of elements.
alignmentThe alignment needed for the allocation.
Returns
An allocation fitting the conditions given, if possible. If not, it will return a default constructed object.
Remarks
Typically, a failure in allocating an object is due to the page size being too small.

◆ reset()

template<typename T = char*, typename U = DefaultMemorySpace>
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.

◆ getCurrentPageFreeMemory()

template<typename T = char*, typename U = DefaultMemorySpace>
unsigned long long nkMemory::LinearPager< T, U >::getCurrentPageFreeMemory ( ) const
Returns
The remaining available size within active page.

The documentation for this class was generated from the following file: