CS::Memory::BlockAllocatorSafe< T, Allocator, ObjectDispose, SizeComputer > Class Template Reference (Crystal Space 2.0 Public API Reference)

| ## Public API Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions
CS::Memory::BlockAllocatorSafe< T, Allocator, ObjectDispose, SizeComputer > Class Template Reference

Thread-safe allocator for objects of a class. More...

`#include <csutil/blockallocator.h>`

Inheritance diagram for CS::Memory::BlockAllocatorSafe< T, Allocator, ObjectDispose, SizeComputer >:

List of all members.

## Public Member Functions
T * | Alloc ()
| Allocate a new object.
template<typename A1 , typename A2 >
T * | Alloc (A1 &a1, A2 &a2)
| Allocate a new object.
template<typename A1 , typename A2 , typename A3 >
T * | Alloc (A1 &a1, A2 &a2, A3 &a3)
| Allocate a new object.
template<typename A1 >
T * | Alloc (A1 &a1)
| Allocate a new object.
void | Compact ()
| Compact the allocator so that all blocks that are completely unused are removed.
void | DeleteAll ()
| Destroy all objects allocated by the pool and release the memory.
void | Empty ()
| Destroy all objects allocated by the pool without releasing the memory.
void | Free (T *p)
| Deallocate an object.
bool | TryFree (T *p)
| Try to delete an object.

## Detailed Description

### template<class T, typename Allocator = AllocatorMalloc, typename ObjectDispose = csBlockAllocatorDisposeDelete<T>, typename SizeComputer = csBlockAllocatorSizeObject<T>>
class CS::Memory::BlockAllocatorSafe< T, Allocator, ObjectDispose, SizeComputer >

Thread-safe allocator for objects of a class.

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

Definition at line 295 of file blockallocator.h.

## Member Function Documentation

template<class T, typename Allocator = AllocatorMalloc, typename ObjectDispose = csBlockAllocatorDisposeDelete<T>, typename SizeComputer = csBlockAllocatorSizeObject<T>>

T* CS::Memory::BlockAllocatorSafe< T, Allocator, ObjectDispose, SizeComputer >::Alloc | ( |  | ) | `[inline]`

Allocate a new object.

The default (no-argument) constructor of T is invoked.

Reimplemented from csBlockAllocator< T, Allocator, ObjectDispose, SizeComputer >.

Definition at line 326 of file blockallocator.h.

template<class T, typename Allocator = AllocatorMalloc, typename ObjectDispose = csBlockAllocatorDisposeDelete<T>, typename SizeComputer = csBlockAllocatorSizeObject<T>>
template<typename A1 , typename A2 >

T* CS::Memory::BlockAllocatorSafe< T, Allocator, ObjectDispose, SizeComputer >::Alloc | ( | A1 & | a1,
|  | A2 & | a2
| ) |  | `[inline]`

Allocate a new object.

The two-argument constructor of T is invoked.

Reimplemented from csBlockAllocator< T, Allocator, ObjectDispose, SizeComputer >.

Definition at line 333 of file blockallocator.h.

template<class T, typename Allocator = AllocatorMalloc, typename ObjectDispose = csBlockAllocatorDisposeDelete<T>, typename SizeComputer = csBlockAllocatorSizeObject<T>>
template<typename A1 , typename A2 , typename A3 >

T* CS::Memory::BlockAllocatorSafe< T, Allocator, ObjectDispose, SizeComputer >::Alloc | ( | A1 & | a1,
|  | A2 & | a2,
|  | A3 & | a3
| ) |  | `[inline]`

Allocate a new object.

The three-argument constructor of T is invoked.

Reimplemented from csBlockAllocator< T, Allocator, ObjectDispose, SizeComputer >.

Definition at line 340 of file blockallocator.h.

template<class T, typename Allocator = AllocatorMalloc, typename ObjectDispose = csBlockAllocatorDisposeDelete<T>, typename SizeComputer = csBlockAllocatorSizeObject<T>>
template<typename A1 >

T* CS::Memory::BlockAllocatorSafe< T, Allocator, ObjectDispose, SizeComputer >::Alloc | ( | A1 & | a1 | ) | `[inline]`

Allocate a new object.

The one-argument constructor of T is invoked.

Reimplemented from csBlockAllocator< T, Allocator, ObjectDispose, SizeComputer >.

Definition at line 347 of file blockallocator.h.

template<class T, typename Allocator = AllocatorMalloc, typename ObjectDispose = csBlockAllocatorDisposeDelete<T>, typename SizeComputer = csBlockAllocatorSizeObject<T>>

void CS::Memory::BlockAllocatorSafe< T, Allocator, ObjectDispose, SizeComputer >::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< SizeComputer::value, Allocator >.

Definition at line 320 of file blockallocator.h.

template<class T, typename Allocator = AllocatorMalloc, typename ObjectDispose = csBlockAllocatorDisposeDelete<T>, typename SizeComputer = csBlockAllocatorSizeObject<T>>

void CS::Memory::BlockAllocatorSafe< T, Allocator, ObjectDispose, SizeComputer >::DeleteAll | ( |  | ) | `[inline]`

Destroy all objects allocated by the pool and release the memory.

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

Reimplemented from csBlockAllocator< T, Allocator, ObjectDispose, SizeComputer >.

Definition at line 314 of file blockallocator.h.

template<class T, typename Allocator = AllocatorMalloc, typename ObjectDispose = csBlockAllocatorDisposeDelete<T>, typename SizeComputer = csBlockAllocatorSizeObject<T>>

void CS::Memory::BlockAllocatorSafe< T, Allocator, ObjectDispose, SizeComputer >::Empty | ( |  | ) | `[inline]`

Destroy all objects allocated by the pool without releasing the memory.

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

Reimplemented from csBlockAllocator< T, Allocator, ObjectDispose, SizeComputer >.

Definition at line 308 of file blockallocator.h.

template<class T, typename Allocator = AllocatorMalloc, typename ObjectDispose = csBlockAllocatorDisposeDelete<T>, typename SizeComputer = csBlockAllocatorSizeObject<T>>

void CS::Memory::BlockAllocatorSafe< T, Allocator, ObjectDispose, SizeComputer >::Free | ( | T * | p | ) | `[inline]`

Deallocate an object.

It is safe to provide a null pointer.

Parameters:

  p | Pointer to deallocate.

Reimplemented from csBlockAllocator< T, Allocator, ObjectDispose, SizeComputer >.

Definition at line 353 of file blockallocator.h.

template<class T, typename Allocator = AllocatorMalloc, typename ObjectDispose = csBlockAllocatorDisposeDelete<T>, typename SizeComputer = csBlockAllocatorSizeObject<T>>

bool CS::Memory::BlockAllocatorSafe< T, Allocator, ObjectDispose, SizeComputer >::TryFree | ( | T * | p | ) | `[inline]`

Try to delete an object.

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 csBlockAllocator< T, Allocator, ObjectDispose, SizeComputer >.

Definition at line 358 of file blockallocator.h.

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

- csutil/blockallocator.h