NAME
OTC_Pool -
A fast memory allocator.
SYNOPSIS
#include <OTC/memory/pool.hh>
class OTC_Pool
{
public:
static os_typespec* get_os_typespec();
OTC_Pool(size_t theSize);
inline OTC_Pool(size_t theSize, size_t theBlockSize);
~OTC_Pool();
inline size_t elementSize() const;
inline void* allocate();
inline void release(void* theMemory);
};
CLASS TYPE
Concrete
DESCRIPTION
This is a fast memory allocator modelled after a Pool class by Dag
Bruck. which was in turn modelled after the Pool class in the USL
C++ Class Library.
CONSTRUCTION
Note that the constructors do not allocate an initial block of
memory. The first block will only be allocated the first time
allocate() is called. If the maximum block size is not of
sufficient size to hold one block and enough space for internal
requirements, more than the maximum size will be allocated.
OTC_Pool(size_t theSize);
Creates a pool for blocks of memory of
theSize. If the environment variable
OTCLIB_POOLBLOCKSIZE is set to an
integer value, it will be used as the
the maximum block size when allocating
new blocks of memory from the operating
system. If the environment variable is not
defined, a default of 2040 bytes will be
used.
inline OTC_Pool(size_t theSize, size_t theBlockSize);
Creates a pool for blocks of memory of
theSize. The value theBlockSize, will
be used as the maximum block size when
allocating new blocks of memory from the
operating system.
DESTRUCTION
~OTC_Pool();
Returns all memory allocated by the pool
to the operating system, unless there is
still memory allocated to the user, in
which case an exception is raised.
QUERY
inline size_t elementSize() const;
Returns the size of the elements being
allocated by the pool.
ALLOCATION/DEALLOCATION
inline void* allocate();
A new element is allocated from the pool
and returned. If there are no free
elements, more memory will be allocated
from the operating system.
inline void release(void* theMemory);
The element of the pool addressed by
theMemory is freed. The element must
have been allocated from this pool. If the
memory was not from this pool, the results
are undefined.
LIBRARY
OTC
AUTHOR(S)
Graham Dumpleton
COPYRIGHT
Copyright 1993 OTC LIMITED
Copyright 1994 DUMPLETON SOFTWARE CONSULTING PTY LIMITED