Manual Page Result
0
Command: pool | Section: 3 | Source: UNIX v10 | File: pool.3
POOL(3+) POOL(3+)
NAME
pool - fast memory allocation
SYNOPSIS
#include <Pool.h>
struct Pool {
Pool(unsigned);
~Pool();
void* alloc();
void free(void*)
};
DESCRIPTION
Every is a collection of elements, each of which is an array of bytes.
All elements of a pool are the same size. Pool functions are
Pool(n) Construct a pool whose elements are of size n.
p.alloc() Allocate a new element in pool Return a pointer to the ele-
ment.
p.free(ep) Free the element of p pointed to by ep. The element must
have been allocated from p.
Destroying a pool frees all the memory occupied by its elements.
The memory in a pool element is aligned on the same boundary as memory
returned by malloc(3) so that it may be used to contain an object of
any type. In typical use, there would be one pool per class, with the
pool known only to the new and delete operators of that class.
Performance
Pool memory is allocated in chunks that are typically about 1,000 bytes
each. Once a chunk is allocated to a particular pool, that chunk is
only released when the pool itself is destroyed.
Elements are allocated inline except when a new chunk must be added to
the pool. Elements are always freed inline.
EXAMPLES
#include <Pool.h>
struct Mytype {
static Pool mypool;
// constructors and members
void* operator new(unsigned) { return mypool.alloc(); }
void operator delete(void* p) { mypool.free(p); }
};
Pool Mytype::mypool(sizeof(Mytype));
SEE ALSO
malloc(3)
POOL(3+)