This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

BIOS.heapSize vs Program.heap

Other Parts Discussed in Thread: SYSBIOS

sysbios 6.33.00.19

What's the difference between BIOS.heapSize and Program.heap?  Which one controls the malloc() heap?  The BIOS User Guide says in Section E.2.1 "Removing the malloc heap" that you would do so by modifying Program.heap.  However, Section 6.7.5 of the same document says that to modify the size of the malloc() heap you should modify BIOS.heapSize.  ???

Thanks,
Brad

  • Brad,

    Sorry for the confusion. I'm not sure my explanation will completely clear it up but here goes:

    In a non-SYS/BIOS application, Program.heap controls the size of the malloc() heap.

    In a SYS/BIOS application, BIOS.heapSize is intended to be used to define the malloc() heap size.

    This difference is an attempt to eliminate the wasted memory problem that occurs when two separate memory managers are used.

    SYS/BIOS is designed internally to use the xdc.runtime.Memory module to allocate memory.

    By default, BIOS wires up the xdc.runtime.Memory module to use the ti.sysbios.heaps.HeapMem module to manage memory and sets Program.heap to zero.

    With this default configuration, BIOS also replaces the normal rts malloc() function with one that uses xdc.runtime.Memory instead so that malloc() and Memory_alloc() both use the same heap manager.

    If BIOS did not replace the rts malloc() function, there would then be two memory managers in the system.

    In this way, the BIOS.heapSize parameter controls the size of the malloc() heap.

    I hope this helps a little...

    Alan

  • That helped a bit.  I decided to run a quick test to see what happens when you specify Program.heap in a SYSBIOS application.  I probably should have tried that simple test first, because the result was quite clear.  When I specified a non-zero value for Program.heap I received the following warning:

    BIOS.heapSize and Program.heap have both been set.  Program.heap ignored.  Using BIOS.heapSize.

    I also confirmed by looking at the linker command file that no memory was allocated as a result of Program.heap, i.e. it was truly ignored as stated in the warning.  So that's good news.  So I think in summary:

    • For non-bios programs you specify heap size using Program.heap and it would utilize the rts malloc() function.
    • For bios programs you would specify heap size through BIOS.heapSize.  The Program.heap is a "don't care" in this case as it is completely ignored.  The malloc() implementation will come from ti.sysbios.heaps.HeapMem.  Of course, rather than using malloc() it would be preferable to call Memory_alloc unless you're reusing legacy code or something along those lines.

  • Nicely summarized, Brad! Thanks.

    I'll reference this post for other BIOS.heapSize questions that come up.

    Alan