ARM Technical Support Knowledge Articles

INIT_MEMPOOL REQUIRES MORE MEMORY THAN IS ACTUALLY USED

Applies to: C51 C Compiler

Answer


Information in this article applies to:


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).

Article last edited on: 2004-06-16 15:41:34

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential