<< Previous | Next >> | |
|
int pool_init( Pool_t * p, void * base, word nel, word elsize );
Description
- Initialize a root memory pool. A pool is a linked list of fixed-size blocks taken from a contiguous area. You can use pools instead of
malloc()
when fixed-size blocks are all that is needed. You can have several pools, with different size blocks. Using memory pools is very efficient compared with more general functions likemalloc()
. (There is currently nomalloc()
implementation with Dynamic C.)
- This function should only be called once, at program startup time, for each pool to be used.
- Note: the product of
nel
andelsize
must be less than 65535 (however, this will usually be limited further by the actual amount of root memory available).
- After calling this function, your application must not change any of the fields in the
Pool_t
structure.Parameters
- p
- Pool handle structure. This is allocated by the caller, but this function will initialize it. Normally, this would be allocated in static memory by declaring a global variable of type
Pool_t
.
- base
- Base address of the root data memory area to be managed in this pool. This must be
nel*elsize
bytes long. Typically, this would be a static (global) array.
- nel
- Number of elements in the memory area. 1..32767
- elsize
- Size of each element in the memory area. 2..32767
Return value
- Currently always zero. If you define the macro
POOL_DEBUG
, then parameters are checked. If the parameters look bad, then an exception is raised. You can definePOOL_VERBOSE
to getprintf()
messages.Library
- POOL.LIB
See Also
- pool_xinit, palloc, pcalloc, pfree, phwm, pavail
Dynamic C Functions | << Previous | Next >> | rabbit.com |