Keil Logo

C51: INIT_MEMPOOL REQUIRES MORE MEMORY THAN IS ACTUALLY USED


Information in this article applies to:

  • C51 Version 5.50
  • C51 Version 6.00 Beta
  • C51 Version 6.00

SYMPTOMS

I'm using the memory allocation routines and I have noticed that malloc doesn't let me allocate all of the memory that I've specified in init_mempool. For example, if I specify a heap of 1000 bytes, malloc won't let me allocate all 1000 bytes. What's wrong?

CAUSE

The memory allocation routines maintain information for each allocated and free block in the heap. This requires a small amount of memory for each block that is allocated (and unallocated). For this reason, you can't access the full 1000 bytes that you specified in the call to init_mempool.

RESOLUTION

Specify a larger heap in the call to init_mempool. The memory allocation routine require 5 bytes of extra space for each allocated block. So, if you will allocate 100 10-byte blocks, be sure to add 5 bytes for each block. That will require 1500 bytes of heap (not just 1000).

Last Reviewed: Wednesday, June 16, 2004


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.