# while creating a task, 4 times the ram is malloc'd than requested  @ prvAllocateTCBAndStack()

**URL:** <https://forums.freertos.org/t/while-creating-a-task-4-times-the-ram-is-mallocd-than-requested-prvallocatetcbandstack/6132>\
**Category:** Kernel\
**Created:** [August 26, 2016, 3:35pm UTC](https://forums.freertos.org/t/while-creating-a-task-4-times-the-ram-is-mallocd-than-requested-prvallocatetcbandstack/6132 "2016-08-26T15:35:24Z")\
**Posts on this page:** 4\
**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:** [August 26, 2016, 3:35pm UTC](https://forums.freertos.org/t/while-creating-a-task-4-times-the-ram-is-mallocd-than-requested-prvallocatetcbandstack/6132/1 "2016-08-26T15:35:24Z")

</div>

**[hassan789](https://sourceforge.net/u/hassan789/)** wrote on [Friday, August 26, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/171493c1/#a05a):

When createing a task with 4kB of stack, prvAllocateTCBAndStack() executes the following line:

`pxNewTCB->pxStack = ( StackType_t * ) pvPortMallocAligned( ( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ) ), puxStackBuffer ); `

This does a mallco of 4kB \* sizeof( StackType\_t )… which means it mallocs 16kB… why is that?

I am running FreeRTOS v8 and Heap4

Thanks

---

<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:** [August 26, 2016, 3:43pm UTC](https://forums.freertos.org/t/while-creating-a-task-4-times-the-ram-is-mallocd-than-requested-prvallocatetcbandstack/6132/2 "2016-08-26T15:43:35Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Friday, August 26, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/171493c1/#a05a/bc6f):

Please see the documentation for the xTaskCreate() API function:  
[http://www.freertos.org/a00125.html](http://www.freertos.org/a00125.html)

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [August 26, 2016, 3:45pm UTC](https://forums.freertos.org/t/while-creating-a-task-4-times-the-ram-is-mallocd-than-requested-prvallocatetcbandstack/6132/3 "2016-08-26T15:45:11Z")

</div>

**[richard\_damon](https://sourceforge.net/u/richard_damon/)** wrote on [Friday, August 26, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/171493c1/#4dc7):

Requested stack size is define to be in units of StackType\_T, not bytes. Due to alignment reasons, it MUST be a multiple of StackType\_T, so it is given in units of StackType\_T.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [August 26, 2016, 4:15pm UTC](https://forums.freertos.org/t/while-creating-a-task-4-times-the-ram-is-mallocd-than-requested-prvallocatetcbandstack/6132/4 "2016-08-26T16:15:14Z")

</div>

**[hassan789](https://sourceforge.net/u/hassan789/)** wrote on [Friday, August 26, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/171493c1/#4f0a):

understood… thanks
