CrystalSpace

Public API Reference

CS::Memory::FixedSizeAllocatorSafe< Size, Allocator > Class Template Reference

Thread-safe allocator for blocks of the same size. More...

#include <csutil/fixedsizeallocator.h>

Inheritance diagram for CS::Memory::FixedSizeAllocatorSafe< Size, Allocator >:

List of all members.

Public Member Functions

void * Alloc ()
 Allocate a chunk of memory.
void Compact ()
 Compact the allocator so that all blocks that are completely unused are removed.
void Empty ()
 Destroy all chunks allocated.
size_t GetAllocatedElems () const
 Return number of allocated elements (potentially slow).
size_t GetBlockElements () const
 Query number of elements per block.
bool TryFree (void *p)
 Try to delete a chunk of memory.

Detailed Description

template<size_t Size, class Allocator = CS::Memory::AllocatorMalloc>
class CS::Memory::FixedSizeAllocatorSafe< Size, Allocator >

Thread-safe allocator for blocks of the same size.

Has the same purpose and interface as csFixedSizeAllocator but is safe to be used concurrently from different threads.

Definition at line 522 of file fixedsizeallocator.h.


Member Function Documentation

template<size_t Size, class Allocator = CS::Memory::AllocatorMalloc>
void* CS::Memory::FixedSizeAllocatorSafe< Size, Allocator >::Alloc (  )  [inline]

Allocate a chunk of memory.

Reimplemented from csFixedSizeAllocator< Size, Allocator >.

Definition at line 561 of file fixedsizeallocator.h.

template<size_t Size, class Allocator = CS::Memory::AllocatorMalloc>
void CS::Memory::FixedSizeAllocatorSafe< Size, Allocator >::Compact (  )  [inline]

Compact the allocator so that all blocks that are completely unused are removed.

The blocks that still contain elements are not touched.

Reimplemented from csFixedSizeAllocator< Size, Allocator >.

Definition at line 549 of file fixedsizeallocator.h.

template<size_t Size, class Allocator = CS::Memory::AllocatorMalloc>
void CS::Memory::FixedSizeAllocatorSafe< Size, Allocator >::Empty (  )  [inline]

Destroy all chunks allocated.

Remarks:
All pointers returned by Alloc() are invalidated. It is safe to perform new allocations from the pool after invoking Empty().

Reimplemented from csFixedSizeAllocator< Size, Allocator >.

Definition at line 543 of file fixedsizeallocator.h.

template<size_t Size, class Allocator = CS::Memory::AllocatorMalloc>
size_t CS::Memory::FixedSizeAllocatorSafe< Size, Allocator >::GetAllocatedElems (  )  const [inline]

Return number of allocated elements (potentially slow).

Reimplemented from csFixedSizeAllocator< Size, Allocator >.

Definition at line 555 of file fixedsizeallocator.h.

template<size_t Size, class Allocator = CS::Memory::AllocatorMalloc>
size_t CS::Memory::FixedSizeAllocatorSafe< Size, Allocator >::GetBlockElements (  )  const [inline]

Query number of elements per block.

Reimplemented from csFixedSizeAllocator< Size, Allocator >.

Definition at line 573 of file fixedsizeallocator.h.

template<size_t Size, class Allocator = CS::Memory::AllocatorMalloc>
bool CS::Memory::FixedSizeAllocatorSafe< Size, Allocator >::TryFree ( void *  p  )  [inline]

Try to delete a chunk of memory.

Usage is the same as Free(), the difference being that false is returned if the deallocation failed (the reason is most likely that the memory was not allocated by the allocator).

Reimplemented from csFixedSizeAllocator< Size, Allocator >.

Definition at line 568 of file fixedsizeallocator.h.


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

Generated for Crystal Space 2.1 by doxygen 1.6.1