 | C251 User's Guide |  |
|
|
| finit_mempool| Summary |
#include <stdlib.h>
void finit_mempool (
void far *p, /* start of memory pool */
unsigned long size); /* length of memory pool */
| | Description | The finit_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 fcalloc, ffree, fmalloc, and frealloc 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 (fcalloc, ffree, fmalloc, frealloc) can be called. Call the finit_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.
- Each memory block needs 8 bytes overhead to handle the allocation information. In addition another 8 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 224 bytes.
| | Return Value | None. | | Example |
#include <stdlib.h>
void tst_init_mempool (void) {
xdata void *p;
int i;
/* initialize memory pool at xdata 0x2000 for 4096 bytes */
finit_mempool (&XBYTE [0x2000], 0x1000);
p = fmalloc (100);
for (i = 0; i < 100; i++)
((char *) p)[i] = i;
ffree (p);
}
|
|
|