|
| init_mempool| Summary | |
#include <stdlib.h>
void init_mempool (
void far *p, /* start of memory pool */
size_t size); /* length of memory pool */
or
void init_mempool (
void huge *p, /* start of memory pool */
size_t size); /* length of memory pool */
or
void init_mempool (
void xhuge *p, /* start of memory pool */
size_t size); /* length of memory pool */
| | Description | | The init_mempool 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 in xdata which is managed using the calloc, free, malloc, and realloc 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, free, malloc, realloc) can be called. Call the init_mempool 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 and return values are far in Small, Medium, Compact, and Large Memory Models; huge in HCompact and HLarge Memory Models; and xhuge in the XLarge Memory Model. 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, free, malloc, realloc | | Example | |
#include <stdlib.h>
unsigned int malloc_mempool [0x800]; // 4KB memory pool
void tst_init_mempool (void) {
int i;
void far *p;
init_mempool (&malloc_mempool, sizeof(malloc_mempool));
p = malloc (100);
for (i = 0; i < 100; i++)
((char *) p)[i] = i;
free (p);
}
|
|
|