init_mempool
Hello All,
Can anyone judge the following code of init_mem.c.
Here is the code for init_mem.c
void init_mempool (
void *pool, /* address of the memory pool */
unsigned int size) { /* size of the pool in bytes */
/* Set the __mp__ to point to the beginning of the pool and set
* the pool size.
*/
__mp__ = (struct __mp__ *) ((unsigned int)((unsigned int)pool+3)&~3);
/* Set the link of the block in the pool to NULL (since it's the only
* block) and initialize the size of its data area.
*/
((struct __mp__ *) pool)->next = NULL;
((struct __mp__ *) pool)->len = size - HLEN;
}
Here is the way I try to use it:
unsigned char memory_pool[0x4000];
void main (void)
{
init_mempool (memory_pool, sizeof(memory_pool));
Rx_Data_Buffer = (char *)calloc(10, 1);
free (Rx_Data_Buffer);
}
The above init_mempool() fails, but when I give the start address of RAM
and its total size as parameters to init_mempool(), it works.
How will I be able to assign limited portion of RAM as HEAP?
Regards,
John