Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Heap initialisation...

Status
Not open for further replies.

john2020

Full Member level 5
Full Member level 5
Joined
Nov 13, 2005
Messages
292
Helped
12
Reputation
24
Reaction score
8
Trophy points
1,298
Visit site
Activity points
4,911
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
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top