object_pool - Boost Object Pool Allocator

Introduction

object_pool.hpp provides a template type that can be used for fast and
efficient memory allocation. It also provides automatic destruction of
non-deallocated objects. For information on other pool-based interfaces, see
the other pool interfaces.

Template Parameters

ElementType

The template parameter is the type of object to allocate/deallocate. It
must have a non-throwing destructor.

UserAllocator

Defines the method that the underlying Pool will use to allocate memory
from the system. See User Allocators for
details.

Semantics

Symbol Table

Symbol

Meaning

ObjectPool

object_pool<ElementType, UserAllocator>

t

value of type ObjectPool

u

value of type const ObjectPool

p

value of type ElementType *

Typedefs

Expression

Type

ObjectPool::element_type

ElementType

ObjectPool::user_allocator

UserAllocator

ObjectPool::size_type

pool<UserAllocator>::size_type

ObjectPool::difference_type

pool<UserAllocator>::difference_type

Constructors, Destructors, and Testing

Expression

Return Type

Notes

ObjectPool()

not used

Constructs a new empty ObjectPool

(&t)->~ObjectPool()

not used

Destructs the ObjectPool; ~ElementType() is called for each allocated ElementType
that has not been deallocated. O(N).

u.is_from(p)

bool

Returns true if p was allocated from u or may be
returned as the result of a future allocation from u. Returns false if
p was allocated from some other pool or may be
returned as the result of a future allocation from some other pool.
Otherwise, the return value is meaningless; note that this function may
not be used to reliably test random pointer values.

Allocation and Deallocation

Expression

Return Type

Pre-Condition

Semantic Equivalence

Notes

t.malloc()

ElementType *

Allocates memory that can hold an object of type ElementType. If out of memory, returns 0. Amortized O(1).

t.free(p)

not used

p must have been previously allocated from
t

Deallocates a chunk of memory. Note that p may not be 0. Note that the
destructor for p is not called. O(N).

t.construct(???)

ElementType *

ElementType must have a constructor
matching ???; the number of parameters given
must not exceed what is supported through pool_construct

Allocates and initializes an object of type ElementType. If out of memory, returns 0. Amortized O(1).