All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Public Member Functions | List of all members
b2SlabAllocator< T > Class Template Reference

#include <b2SlabAllocator.h>

Public Member Functions

 b2SlabAllocator (const uint32 itemsPerSlab)
 ~b2SlabAllocator ()
 Free all allocated slabs.
void SetItemsPerSlab (uint32 itemsPerSlab)
uint32 GetItemsPerSlab () const
T * Allocate ()
 Allocate a item from the slab.
void Free (T *object)
 Free an item from the slab.
bool AllocateSlab ()
void FreeAllSlabs ()
 Free all slabs.
void FreeEmptySlabs ()
const b2TypedFreeList< T > & GetFreeList () const
 Get the item allocator freelist.

Detailed Description

template<typename T>
class b2SlabAllocator< T >

Freelist based allocator for fixed sized items from slabs (memory preallocated from the heap). T should be a class which has a default constructor and implements the member function "b2IntrusiveList* GetListNode()". All objects in a slab are constructed when a slab is created and destructed when a slab is freed.

Constructor & Destructor Documentation

template<typename T>
b2SlabAllocator< T >::b2SlabAllocator ( const uint32  itemsPerSlab)

Initialize the allocator to allocate itemsPerSlab of type T for each slab that is allocated.

Member Function Documentation

template<typename T>
bool b2SlabAllocator< T >::AllocateSlab ( )

Allocate a slab, construct instances of T and add them to the free pool.

template<typename T>
void b2SlabAllocator< T >::FreeEmptySlabs ( )

Free all empty slabs. This method is slow - O(M^N) - since this class doesn't track the association between each item and slab.

template<typename T>
void b2SlabAllocator< T >::SetItemsPerSlab ( uint32  itemsPerSlab)

Set size of the next allocated slab using the number of items per slab. Setting this value to zero disables further slab allocation.

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