Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

Create a task uses how much heap?

Posted by Bonanza35 on January 8, 2009

Where can I find out how much heap is used in creating a task, and what things affect the amount of heap used? I know it's going to be different for different platforms. I'm using an ARM7 and it seems like the minimum is 404 bytes, often 532 or 660 bytes, and one of my tasks uses 812 bytes off the heap on creation. Do these all look reasonable, and why the differences?

RE: Create a task uses how much heap?

Posted by Dave on January 8, 2009
Ram used = sizeof( tskTCB ) + ( usStackSize * sizeof( portSTACK_TYPE ) )

usStackSize is the parameter passed to xTaskCreate().
portSTACK_TYPE is unsigned long on an ARM7.

There may also be a couple of extra bytes to ensure the correct alignment.




RE: Create a task uses how much heap?

Posted by Bonanza35 on January 8, 2009

>>> Ram used = sizeof( tskTCB ) + ( usStackSize * sizeof( portSTACK_TYPE ) )

Good afternoon, Dave.

How much of that comes from the heap? I assume (usStackSize * sizeof(portSTACK_TYPE)) goes in the stack area, right?

Heap usage for tasks startups for three representative tasks are 404, 532, and 660 bytes. Stack allocations are 64, 96, and 128 respectively. Per the formula above, then, the RAM usage should be 396, 524, and 652 respectively. Each calculated value is 8 bytes below the actual value, so I assume the extra 8 bytes are overhead plus alignment.

It does look like each task is taking heap memory for its stack. Project configuration for the IAR compiler has a STACKS segment (576 bytes) and a HEAP segment (10752 bytes). If the tasks build their stacks on the heap, what is the STACKS segment for?

RE: Create a task uses how much heap?

Posted by Dave on January 9, 2009
>How much of that comes from the heap? I assume (usStackSize
>* sizeof(portSTACK_TYPE)) goes in the stack area, right?


The memory is used as the stack for the task but comes from the FreeRTOS heap - heap_1, heap_2, heap_3, or whatever you have used.

The stack segment is used for main() before the kernel starts but can be used for whatever you like after that. You can use it for the IRQ stack to avoid allocating memory for both.

The heap segment setup by the compiler is only used if you are using heap_3 or calling malloc() directory (instead of pvPortMalloc). If you are not doing either of these then set it to its minimum value, probably 4.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10.0.1 is available for immediate download. Now MIT licensed.

Video: Watch James Gosling & Richard Barry at re:Invent, Las Vegas 2017.

New FAQ page about the FreeRTOS kernel and Amazon FreeRTOS.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner