 | C166 User's Guide |  |
|
|
| init_mempool_b| Summary |
#include <stdlib.h>
void init_mempool_b (
void xhuge *p, /* start of memory pool */
unsigned long size); /* length of memory pool */
| | Description | The init_mempool_b function initializes the memory management routines and provides the starting address and size of the memory pool. The p argument points to a memory area which is managed using the calloc_b, free_b, malloc_b, and realloc_bb library functions. The size argument specifies the number of bytes to use for the memory pool. Note - This function must be used to setup the memory pool before any other memory management functions (calloc_b, free_b, malloc_b, realloc_b) can be called. Call the init_mempool_b function only once at the beginning of your program.
- Source code for this routine is provide in the LIB folder. You may modify the source to customize this function for your particular hardware environment.
- Pointer arguments are xhuge in all memory models. This function is not supported in the Tiny Memory Model.
- Each memory block needs 6 bytes overhead to handle the allocation information. In addition another 6 bytes are required for init_mempool itself. Therefore if you want to allocate 2 blocks with 100 bytes each, the memory pool size must be 218 bytes.
| | Return Value | None. | | See Also | calloc_b, free_b, malloc_b, realloc_b | | Example |
#include <stdlib.h>
char memory_pool [0x1000];
void tst_init_mempool_b (void) {
void far *p;
int i;
/* initialize memory pool */
init_mempool_b (memory_pool, sizeof(memory_pool));
p = malloc_b (100);
for (i = 0; i < 100; i++)
((char *) p)[i] = i;
free_b (p);
}
|
|
|