Nebula
Loading...
Searching...
No Matches
Memory::ArenaAllocator< ChunkSize > Class Template Reference

#include <arenaallocator.h>

Detailed Description

template<int ChunkSize>
class Memory::ArenaAllocator< ChunkSize >

Allocates memory in chunks.

This allocator creates memory in user-specified (default 65535) byte chunks. Each time an object is requested, the current chunk is checked for storage, and if the object fits, an iterator is progressed with the size of the object, after which a pointer to the allocated space is returned. If the object does not fit, the allocator creates a new chunk, and retires the old, without considering the potential space lost in the process.

This type of allocator allows for several objects of different types to be allocated linearly in memory, thus providing a cache-friendly access pattern for places where memory allocation is somewhat deterministic.

Public Member Functions

 ArenaAllocator ()
 constructor
 
 ~ArenaAllocator ()
 destructor
 
 ArenaAllocator (const ArenaAllocator &rhs)
 copy constructor
 
void operator= (const ArenaAllocator &rhs)
 assignment operator
 
 ArenaAllocator (ArenaAllocator &&rhs)
 move constructor
 
void operator= (ArenaAllocator &&rhs)
 move operator
 
template<typename T >
T * Alloc ()
 allocate new object, and calls constructor, but beware because this allocator does not run the destructors
 
template<typename T >
T * Alloc (SizeT num)
 Allocate several new objects of a specific type.
 
void * Alloc (SizeT size)
 allocate new chunk of size
 
void NewChunk ()
 retires a chunk and creates a new one (might waste memory)
 
void Release ()
 release all memory
 

Private Attributes

byte * currentChunk
 
byte * iterator
 
Util::Array< byte * > retiredChunks
 

Constructor & Destructor Documentation

◆ ArenaAllocator() [1/3]

template<int ChunkSize>
Memory::ArenaAllocator< ChunkSize >::ArenaAllocator ( )
inline

constructor

◆ ~ArenaAllocator()

template<int ChunkSize>
Memory::ArenaAllocator< ChunkSize >::~ArenaAllocator ( )
inline

destructor

◆ ArenaAllocator() [2/3]

template<int ChunkSize>
Memory::ArenaAllocator< ChunkSize >::ArenaAllocator ( const ArenaAllocator< ChunkSize > & rhs)
inline

copy constructor

◆ ArenaAllocator() [3/3]

template<int ChunkSize>
Memory::ArenaAllocator< ChunkSize >::ArenaAllocator ( ArenaAllocator< ChunkSize > && rhs)
inline

move constructor

Member Function Documentation

◆ Alloc() [1/3]

template<int ChunkSize>
template<typename T >
T * Memory::ArenaAllocator< ChunkSize >::Alloc ( )
inline

allocate new object, and calls constructor, but beware because this allocator does not run the destructors

◆ Alloc() [2/3]

template<int ChunkSize>
template<typename T >
T * Memory::ArenaAllocator< ChunkSize >::Alloc ( SizeT num)
inline

Allocate several new objects of a specific type.

◆ Alloc() [3/3]

template<int ChunkSize>
void * Memory::ArenaAllocator< ChunkSize >::Alloc ( SizeT size)
inline

allocate new chunk of size

◆ NewChunk()

template<int ChunkSize>
void Memory::ArenaAllocator< ChunkSize >::NewChunk ( )
inline

retires a chunk and creates a new one (might waste memory)

◆ operator=() [1/2]

template<int ChunkSize>
void Memory::ArenaAllocator< ChunkSize >::operator= ( ArenaAllocator< ChunkSize > && rhs)
inline

move operator

◆ operator=() [2/2]

template<int ChunkSize>
void Memory::ArenaAllocator< ChunkSize >::operator= ( const ArenaAllocator< ChunkSize > & rhs)
inline

assignment operator

◆ Release()

template<int ChunkSize>
void Memory::ArenaAllocator< ChunkSize >::Release ( )
inline

release all memory

Member Data Documentation

◆ currentChunk

template<int ChunkSize>
byte* Memory::ArenaAllocator< ChunkSize >::currentChunk
private

◆ iterator

template<int ChunkSize>
byte* Memory::ArenaAllocator< ChunkSize >::iterator
private

◆ retiredChunks

template<int ChunkSize>
Util::Array<byte*> Memory::ArenaAllocator< ChunkSize >::retiredChunks
private

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