Support Forum       G3D Web Page     
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
G3D::BlockPoolMemoryManager Class Reference

A MemoryManager that allocates fixed-size objects and maintains a freelist that never shrinks. More...

Inherits G3D::ReferenceCountedObject.

Public Member Functions

virtual ~BlockPoolMemoryManager ()
 
virtual void * alloc (size_t s)
 Return a pointer to s bytes of memory that are unused by the rest of the program. More...
 
size_t blockSize () const
 
virtual void free (void *_ptr)
 Invoke to declare that this memory will no longer be used by the program. More...
 
int freeListNumBlocks () const
 Returns the number of blocks currently sitting in the free list. More...
 
virtual bool isThreadsafe () const
 Returns true if this memory manager is threadsafe (i.e., alloc and free can be called asychronously) More...
 
int peakNumBlocks () const
 Total number of blocks ever allocated at once. More...
 

Static Public Member Functions

static shared_ptr< BlockPoolMemoryManagercreate (size_t blockSize)
 Creates a new instance. More...
 

Protected Member Functions

 BlockPoolMemoryManager (size_t s)
 

Static Protected Member Functions

template<class T , class ... ArgTypes>
static shared_ptr< T > createShared (ArgTypes &&... args)
 Like std::make_shared, but works for protected constructors. More...
 

Protected Attributes

Set< uint32 * > m_allBlocks
 
const size_t m_blockSize
 
Array< uint32 * > m_freeList
 
std::mutex m_mutex
 

Detailed Description

A MemoryManager that allocates fixed-size objects and maintains a freelist that never shrinks.

Useful for sharing work buffers among threads.

Constructor & Destructor Documentation

◆ BlockPoolMemoryManager()

G3D::BlockPoolMemoryManager::BlockPoolMemoryManager ( size_t  s)
inlineprotected

Referenced by create().

◆ ~BlockPoolMemoryManager()

virtual G3D::BlockPoolMemoryManager::~BlockPoolMemoryManager ( )
inlinevirtual

Member Function Documentation

◆ alloc()

virtual void* G3D::BlockPoolMemoryManager::alloc ( size_t  s)
inlinevirtual

Return a pointer to s bytes of memory that are unused by the rest of the program.

The contents of the memory are undefined

◆ blockSize()

size_t G3D::BlockPoolMemoryManager::blockSize ( ) const
inline

Referenced by create().

◆ create()

static shared_ptr<BlockPoolMemoryManager> G3D::BlockPoolMemoryManager::create ( size_t  blockSize)
inlinestatic

Creates a new instance.

Each instance is allowed to have its own block size.

◆ createShared()

template<class T , class ... ArgTypes>
static shared_ptr<T> G3D::ReferenceCountedObject::createShared ( ArgTypes &&...  args)
inlinestaticprotectedinherited

Like std::make_shared, but works for protected constructors.

Call as createShared<myclass>.

◆ free()

virtual void G3D::BlockPoolMemoryManager::free ( void *  _ptr)
inlinevirtual

Invoke to declare that this memory will no longer be used by the program.

The memory manager is not required to actually reuse or release this memory.

◆ freeListNumBlocks()

int G3D::BlockPoolMemoryManager::freeListNumBlocks ( ) const
inline

Returns the number of blocks currently sitting in the free list.

◆ isThreadsafe()

virtual bool G3D::BlockPoolMemoryManager::isThreadsafe ( ) const
inlinevirtual

Returns true if this memory manager is threadsafe (i.e., alloc and free can be called asychronously)

◆ peakNumBlocks()

int G3D::BlockPoolMemoryManager::peakNumBlocks ( ) const
inline

Total number of blocks ever allocated at once.

Member Data Documentation

◆ m_allBlocks

Set<uint32*> G3D::BlockPoolMemoryManager::m_allBlocks
protected

Referenced by alloc(), free(), and peakNumBlocks().

◆ m_blockSize

const size_t G3D::BlockPoolMemoryManager::m_blockSize
protected

Referenced by alloc(), and blockSize().

◆ m_freeList

Array<uint32*> G3D::BlockPoolMemoryManager::m_freeList
protected

◆ m_mutex

std::mutex G3D::BlockPoolMemoryManager::m_mutex
mutableprotected

documentation generated on Wed Nov 24 2021 08:01:53 using doxygen 1.8.15