|ARM Technical Support Knowledge Articles|
Applies to: C51 C Compiler
Information in this article applies to:
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?
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.
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).
Article last edited on: 2004-06-16 15:41:34
Did you find this article helpful? Yes No
How can we improve this article?