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

A pager implementing the free list pattern. More...

Public Member Functions

 FreeListPager (unsigned long long pageSize, UniquePtr< MemorySpaceAllocator< U >> allocator=makeUnique< DefaultMemorySpaceAllocator< U >>()) noexcept
 
 FreeListPager (const FreeListPager &) noexcept=delete
 
 FreeListPager (FreeListPager &&) noexcept=default
 
unsigned long long getPageSize () const
 
unsigned long long getAllocatedPageCount () const
 
const FreeListMemorySpaceWrapper< T, U > & getPage (unsigned long long index)
 
FreeListAllocation< T > allocate (unsigned long long size, unsigned long long alignment=1)
 
void free (unsigned long long allocationIndex)
 
FreeListPageroperator= (const FreeListPager &) noexcept=delete
 
FreeListPageroperator= (FreeListPager &&) noexcept=default
 

Detailed Description

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

A pager implementing the free list pattern.

This pattern keeps track of allocations within the pages, and returns allocations fitting the requirements within the memory space allocated. Allocations can be freed individually. This pager can be used when data will be kept around, with no knowledge about the lifetime of it.
For instance, in a 3d renderer, gpu resources can be placed within a memory space as they come and go, reducing the need for memory allocations.

Constructor & Destructor Documentation

◆ FreeListPager() [1/3]

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

Constructor.

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

◆ FreeListPager() [2/3]

template<typename T = char*, typename U = DefaultMemorySpace>
nkMemory::FreeListPager< T, U >::FreeListPager ( const FreeListPager< T, U > &  )
deletenoexcept

Copy constructor.

◆ FreeListPager() [3/3]

template<typename T = char*, typename U = DefaultMemorySpace>
nkMemory::FreeListPager< T, U >::FreeListPager ( FreeListPager< T, U > &&  )
defaultnoexcept

Move constructor.

Member Function Documentation

◆ getPageSize()

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

◆ getAllocatedPageCount()

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

◆ getPage()

template<typename T = char*, typename U = DefaultMemorySpace>
const FreeListMemorySpaceWrapper<T, U>& nkMemory::FreeListPager< T, U >::getPage ( unsigned long long  index)
Returns
Returns a page kept internally. Should not be called by external code.

◆ allocate()

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

Requests an allocation.

Parameters
sizeThe size of the allocation needed, in number of elements.
alignmentThe needed alignment in the memory space.
Returns
An allocation fitting requested conditions, if possible.
Remarks
Typically, a failure in allocating is caused by the page size being too small.

◆ free()

template<typename T = char*, typename U = DefaultMemorySpace>
void nkMemory::FreeListPager< T, U >::free ( unsigned long long  allocationIndex)

Releases an allocation so that it returns within the pager.

Parameters
allocationIndexThe index for the allocation to free. Provided by allocate().

◆ operator=() [1/2]

template<typename T = char*, typename U = DefaultMemorySpace>
FreeListPager& nkMemory::FreeListPager< T, U >::operator= ( const FreeListPager< T, U > &  )
deletenoexcept

Copy assignment.

◆ operator=() [2/2]

template<typename T = char*, typename U = DefaultMemorySpace>
FreeListPager& nkMemory::FreeListPager< T, U >::operator= ( FreeListPager< T, U > &&  )
defaultnoexcept

Move assignment.


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