Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




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) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists