Falcon
Classes | Functions
fmemory Namespace Reference

Classes

class  PoolAllocator
 
class  StackAllocator
 
class  StackSTLAllocator
 
class  STLAllocator
 

Functions

void * AllocateUnaligned (std::size_t sz_in_byte)
 
void Deallocate (void *memref)
 
void * AllocateAligned (std::size_t sz_in_byte, std::size_t alignment)
 
void DeallocateAligned (void *memref)
 
template<typename T , typename... Args>
T * fnew (Args... args)
 
template<typename T , typename... Args>
T * fnew_arr (std::size_t &count, Args... args)
 
template<typename T , typename... Args>
T * fnew_arr (unsigned count, Args... args)
 
template<typename T >
void fdelete (T *ptr)
 
template<typename T >
void fdelete (T *ptr, std::size_t &count)
 
template<typename T , typename... Args>
T * fnew_stack (Args... args)
 
bool MemoryManagerInit ()
 
bool MeoryManagerShutDown ()
 
void * Allocate (const std::size_t size)
 
void Free (void *ref, const std::size_t size)
 
void * AllocateOnStack (const std::size_t size)
 
bool FlushStack ()
 
template<class T , class U >
constexpr bool operator== (const StackSTLAllocator< T > &, const StackSTLAllocator< U > &) noexcept
 
template<class T , class U >
constexpr bool operator!= (const StackSTLAllocator< T > &, const StackSTLAllocator< U > &) noexcept
 
template<class T , class U >
constexpr bool operator== (const STLAllocator< T > &, const STLAllocator< U > &) noexcept
 
template<class T , class U >
constexpr bool operator!= (const STLAllocator< T > &, const STLAllocator< U > &) noexcept
 

Detailed Description

STL container constructors take in an allocators which they use to allocate memory for intenal object allocations. By defualt it uses, std::allocators. Following class provides similar interface which enables STL containers to use our custome allocators.Please use following link to understand std::allocator, https://en.cppreference.com/w/cpp/memory/allocator

All standard containers access these via std::allocators. Thus we don't need to override the construct and destroy methods. Construct creats object inplace with placement new and destroy method calls destructors for the same object without freeing the pointer. Please refer following link for details, https://en.cppreference.com/w/cpp/memory/allocator_traits

Function Documentation

◆ Allocate()

void * fmemory::Allocate ( const std::size_t  size)

Gets you a memory block from available pool. If no pool can accomadate required size it'll create a block using standard memory functions.

Parameters
sizesize of required memory block
Returns
pointer to the allocated space

◆ AllocateAligned()

void * fmemory::AllocateAligned ( std::size_t  sz_in_byte,
std::size_t  alignment 
)

Allocates aligned memory.

Parameters
[in]size_tsize in bytes
[in]size_talignment

◆ AllocateOnStack()

void * fmemory::AllocateOnStack ( const std::size_t  size)

◆ AllocateUnaligned()

void * fmemory::AllocateUnaligned ( std::size_t  sz_in_byte)

Allocates unaligned memory.

Parameters
[in]size_tsize in bytes

◆ Deallocate()

void fmemory::Deallocate ( void *  memref)

Deallocates unaligned memory.

Parameters
[in]void*pointer to the memory

◆ DeallocateAligned()

void fmemory::DeallocateAligned ( void *  memref)

Deallocates aligned memory.

Parameters
[in]void*pointer to the memory

◆ fdelete() [1/2]

template<typename T >
void fmemory::fdelete ( T *  ptr)

◆ fdelete() [2/2]

template<typename T >
void fmemory::fdelete ( T *  ptr,
std::size_t &  count 
)

Deletes the array from memory.

Parameters
pointerto the array @count number of elements in the array

◆ FlushStack()

bool fmemory::FlushStack ( )

◆ fnew()

template<typename T , typename... Args>
T* fmemory::fnew ( Args...  args)

Exposes allocation API to the outer world.

Parameters
Allthe parameters required for calling constructor
Returns
pointer to the memory block allocated.

◆ fnew_arr() [1/2]

template<typename T , typename... Args>
T* fmemory::fnew_arr ( std::size_t &  count,
Args...  args 
)

Exposes allocation API to the outer world.

Parameters
countnumber of elements in the array by ref
Allthe parameters required for calling type constructor
Returns
pointer to the memory block allocated.

◆ fnew_arr() [2/2]

template<typename T , typename... Args>
T* fmemory::fnew_arr ( unsigned  count,
Args...  args 
)

Exposes allocation API to the outer world.

Parameters
countnumber of elements in the array by value
Allthe parameters required for calling type constructor
Returns
pointer to the memory block allocated.

◆ fnew_stack()

template<typename T , typename... Args>
T* fmemory::fnew_stack ( Args...  args)

Exposes allocation API to the outer world.

Parameters
Allthe parameters required for calling constructor
Returns
pointer to the memory block allocated.

◆ Free()

void fmemory::Free ( void *  ref,
const std::size_t  size 
)

Frees the memory block

Parameters
refpointer to the memory block
sizesize of object being deleted, helps find the pool

◆ MemoryManagerInit()

bool fmemory::MemoryManagerInit ( )

Initiates the memory manager. Needs to be called before running any code which uses any fmemory features.

Returns
true if success, otherwise false

Setting up stackAllocator

Setting up pool allocators

◆ MeoryManagerShutDown()

bool fmemory::MeoryManagerShutDown ( )

Shuts down memory manager. Needs to be called at the end of engine's life cycle so as to make sure no memory leaks are present.

Returns
true if success, otherwise false

Deleting stack allocator

Deleting pool allocator

◆ operator!=() [1/2]

template<class T , class U >
constexpr bool fmemory::operator!= ( const StackSTLAllocator< T > &  ,
const StackSTLAllocator< U > &   
)
constexprnoexcept

Compares two default allocators. Since default allocators are stateless, two default allocators are always equal. https://en.cppreference.com/w/cpp/memory/allocator/operator_cmp Always returns false.

◆ operator!=() [2/2]

template<class T , class U >
constexpr bool fmemory::operator!= ( const STLAllocator< T > &  ,
const STLAllocator< U > &   
)
constexprnoexcept

Compares two default allocators. Since default allocators are stateless, two default allocators are always equal. https://en.cppreference.com/w/cpp/memory/allocator/operator_cmp Always returns false.

◆ operator==() [1/2]

template<class T , class U >
constexpr bool fmemory::operator== ( const StackSTLAllocator< T > &  ,
const StackSTLAllocator< U > &   
)
constexprnoexcept

Compares two default allocators. Since default allocators are stateless, two default allocators are always equal. https://en.cppreference.com/w/cpp/memory/allocator/operator_cmp Always returns true.

◆ operator==() [2/2]

template<class T , class U >
constexpr bool fmemory::operator== ( const STLAllocator< T > &  ,
const STLAllocator< U > &   
)
constexprnoexcept

Compares two default allocators. Since default allocators are stateless, two default allocators are always equal. https://en.cppreference.com/w/cpp/memory/allocator/operator_cmp Always returns true.