Pool Class Reference
#include <Pool.H>
Collaboration diagram for Pool:
[legend]List of all members.
Detailed Description
Pool is a class to optimize memory allocation.
Pool is a class to optimize memory allocation. It is specialized to allocate fixed size chunks of memory specified by ptrSize in the constructor. Its operation is analogous to malloc, not new. It does not initialize the memory in any way. The constructor can optionally specify an initial pool size, and memory alignment. The pool size will grow as needed by calling ::new. The pool size never shrinks. Memory will be reclaimed at ~Pool(). The units of poolSize are number-of-ptrSize-chunks. The units of alignment are bytes.
Pool can only be used for objects of fixed size. Typically used in situations where a class or struct is being constantly constructed and deleted. Objects returned by value from functions, elements in a database, etc. Pool's tend to be allocated statically.
from Copier.cpp
Constructor & Destructor Documentation
Pool::Pool |
( |
int |
ptrSize, |
|
|
const char * |
name = "unnamed", |
|
|
int |
poolSize = 100, |
|
|
int |
alignment = sizeof(int) |
|
) |
|
|
|
- Parameters:
-
ptrSize | Size of fixed memory allocations needed |
poolSize | Size of allocations (ptrSize*poolSize) made of the operating system. This controls the granularity of the Pool allocations. Smaller values result in less wasted memory, at the cost of more calls to the operating system for heap memory. |
name | optional name for this Pool. Used in reporting memory by the memory tracking system in Chombo. |
|
Pool::Pool |
( |
const Pool & |
rhs |
) |
[private] |
|
|
Not implemented. Compiler will not let you copy a Pool |
Member Function Documentation
|
request a section of memory of ptrSize_ contiguous bytes.
|
void Pool::returnPtr |
( |
void * |
ptr |
) |
|
|
|
return memory previous acquired with the getPtr() function.
|
long Pool::memUsage |
( |
|
) |
const |
|
|
report how much memory this Pool is currently using.
memUsage for a Pool only grows until Pool destruction. The Pool object has no knowledge of what pieces of memory it has parcelled out to a user, so it keeps it all available. The user is responsible for not leaking Pool memory. |
|
undocumented function, call this at own risk. You must be absolutely positive that you have returned all the ptr's you've asked for, or you can have major seg faults. |
void* Pool::getMoreMemory |
( |
|
) |
[private] |
|
const Pool& Pool::operator= |
( |
const Pool & |
rhs |
) |
[private] |
|
|
Not implemented. Compiler will not let you copy a Pool.
|
Member Data Documentation
The documentation for this class was generated from the following file:
Generated on Fri Jul 2 17:56:01 2004 for Chombo by
1.3.2