# heap\_4 uses more memory that heap\_3

**URL:** <https://forums.freertos.org/t/heap-4-uses-more-memory-that-heap-3/355>\
**Category:** Kernel\
**Created:** [December 18, 2015, 3:27pm UTC](https://forums.freertos.org/t/heap-4-uses-more-memory-that-heap-3/355 "2015-12-18T15:27:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [December 18, 2015, 3:27pm UTC](https://forums.freertos.org/t/heap-4-uses-more-memory-that-heap-3/355/1 "2015-12-18T15:27:41Z")

</div>

**[trob76](https://sourceforge.net/u/trob76/)** wrote on [Friday, December 18, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/0ebf5075/#9194):

I am integrating FreRTOS 8.2.2 into a legacy project. In addition, I am trying to incorporate TCP+ example code. The old coding used heap\_3 for the heap model and the TCP+ requires heap\_4. When I use heap\_4 the build fails saying that the heap memory has overrun it size. I can only use half the size for heap that I need.  
I am using arm\_xilinx\_eabi and an ARM9 in a ZYNQ.

Why are the heap requirements so much more in the heap\_4? Is there a way to use the same heap size?

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [December 18, 2015, 3:40pm UTC](https://forums.freertos.org/t/heap-4-uses-more-memory-that-heap-3/355/2 "2015-12-18T15:40:47Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Friday, December 18, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/0ebf5075/#2e5a):

There are no differences in the amount of heap required or used when switching from heap\_3 to heap\_4, the only difference is how the heap is allocated.

When you use heap\_3 the heap is allocated by the development tools, and does not form part of the data that is located by the linker, and so the linker does not take its size into account.

When you use heap\_4 the heap is basically a statically allocated array, which is located by the linker - and the linker has to fit it into its memory map. The size of the array that is used as the heap is defined by the configTOTAL\_HEAP\_SIZE setting.

Remember that, when using heap\_4, provided no other code is calling malloc directly, you can set the size of the heap allocated by the tools to as close to 0 as the tools will allow (normally 4 bytes).

See [http://www.freertos.org/a00111.html](http://www.freertos.org/a00111.html) for more details.
