VAE - Virtual Audio Engine 1
Small Data Driven Audio Engine
tklb::memory::MemoryPoolStd Class Referencefinal

Pool which proxies allocations to the stdlib. More...

#include <TMemoryPoolStd.hpp>

Inheritance diagram for tklb::memory::MemoryPoolStd:
Collaboration diagram for tklb::memory::MemoryPoolStd:

Public Member Functions

void * allocate (Size size) override
 
void deallocate (void *ptr) override
 
void * reallocate (void *ptr, size_t size) override
 
- Public Member Functions inherited from tklb::memory::MemoryPool
 MemoryPool (void *pool, Size size)
 Construct a pool from memory provided. More...
 
 ~MemoryPool ()
 
Size getAllocated () const
 
Size getTotalSize () const
 
void * clearallocate (size_t num, size_t size)
 Allocates space for num of structs with size size and clears the memory. More...
 
template<class T , typename ... Args>
T * create (Args &&... args)
 Acts like new. More...
 
template<class T , typename ... Args>
T * createArray (size_t count, Args &&... args)
 
template<class T >
void dispose (T *ptr)
 Acts like delete. More...
 
template<class T >
void disposeArray (size_t count, T *ptr)
 Acts like delete. More...
 
void deallocateAligned (void *ptr)
 
void * allocateAligned (const Size size, const Size align=DEFAULT_ALIGN)
 Allocate aligned if simd is enabled. More...
 

Static Public Member Functions

static MemoryPoolStdinstance ()
 The pool uses the standard allocator So no need for multiple instances. More...
 

Private Member Functions

 MemoryPoolStd ()
 

Private Attributes

char mDummyPool [sizeof(SharedPool)]
 
void *(*const mAllocate )(size_t)
 

Additional Inherited Members

- Protected Types inherited from tklb::memory::MemoryPool
using Size = uintptr_t
 
using Byte = unsigned char
 
using Mutex = SpinLock
 
using Lock = LockGuard< Mutex >
 
- Protected Attributes inherited from tklb::memory::MemoryPool
SharedPoolmPool
 
- Static Protected Attributes inherited from tklb::memory::MemoryPool
static constexpr Size DEFAULT_ALIGN = xsimd::default_arch::alignment()
 

Detailed Description

Pool which proxies allocations to the stdlib.

Needs to be included before the monkey patch.

Definition at line 14 of file TMemoryPoolStd.hpp.

Constructor & Destructor Documentation

◆ MemoryPoolStd()

tklb::memory::MemoryPoolStd::MemoryPoolStd ( )
inlineprivate

Definition at line 17 of file TMemoryPoolStd.hpp.

17: MemoryPool(mDummyPool, sizeof(SharedPool)) { }
MemoryPool(void *pool, Size size)
Construct a pool from memory provided.
Definition: TMemoryPool.hpp:76
char mDummyPool[sizeof(SharedPool)]

Member Function Documentation

◆ allocate()

void * tklb::memory::MemoryPoolStd::allocate ( Size  size)
inlineoverridevirtual

Implements tklb::memory::MemoryPool.

Definition at line 36 of file TMemoryPoolStd.hpp.

36 {
37 void* ptr = mAllocate(size + sizeof(Size));
38 if (ptr == nullptr) { return nullptr; }
39 mPool.allocated += size;
40
41 SizeBlock& block = *static_cast<SizeBlock*>(ptr);
42 block.size = size;
43
44 return &block.ptr;
45 }
void *(*const mAllocate)(size_t)
Here is the caller graph for this function:

◆ deallocate()

void tklb::memory::MemoryPoolStd::deallocate ( void *  ptr)
inlineoverridevirtual

Implements tklb::memory::MemoryPool.

Definition at line 47 of file TMemoryPoolStd.hpp.

47 {
48 if (ptr == nullptr) { return; }
49 SizeBlock& block = *reinterpret_cast<SizeBlock*>(
50 static_cast<char*>(ptr) - sizeof(Size)
51 );
52 mPool.allocated -= block.size;
53 return mDeallocate(&block);
54 }

◆ instance()

static MemoryPoolStd & tklb::memory::MemoryPoolStd::instance ( )
inlinestatic

The pool uses the standard allocator So no need for multiple instances.

Definition at line 31 of file TMemoryPoolStd.hpp.

31 {
32 static MemoryPoolStd i;
33 return i;
34 }

◆ reallocate()

void * tklb::memory::MemoryPoolStd::reallocate ( void *  ptr,
size_t  size 
)
inlineoverridevirtual

Implements tklb::memory::MemoryPool.

Definition at line 56 of file TMemoryPoolStd.hpp.

56 {
57 if (ptr == nullptr) {
58 return allocate(size);
59 }
60 void* ptrNew = mReallocate(ptr, size + sizeof(Size));
61
62 SizeBlock& blockOld = *reinterpret_cast<SizeBlock*>(
63 static_cast<char*>(ptr) - sizeof(Size)
64 );
65 mPool.allocated -= blockOld.size;
66 if (ptrNew == nullptr) { return nullptr; }
67
68 mPool.allocated += size;
69
70 SizeBlock& blockNew = *static_cast<SizeBlock*>(ptr);
71 blockNew.size = size;
72
73 return &blockNew.ptr;
74 }
void * allocate(Size size) override
Here is the call graph for this function:

Member Data Documentation

◆ mAllocate

void *(*const tklb::memory::MemoryPoolStd::mAllocate) (size_t)
inlineprivate

Definition at line 18 of file TMemoryPoolStd.hpp.

22 {
23 Size size;
24 void* ptr;
25 };

◆ mDummyPool

char tklb::memory::MemoryPoolStd::mDummyPool[sizeof(SharedPool)]
private

Definition at line 16 of file TMemoryPoolStd.hpp.


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