Quality RTOS & Embedded Software

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


Loading

Static vs Dynamic Configuration

Posted by yevpator75 on January 10, 2019

Hello Sorry for bringing the issue once again here... I carefully read this article https://www.freertos.org/StaticVsDynamicMemoryAllocation.html

Still have doubts and discussions with my colleagues what is the right configuration for our specific project and I wanted to hear other opinions.

Here is a few words about my project.

  1. The project is based on STM32F4 with much RAM.
  2. I am not going to delete objects , like semaphores, tasks and etc in the run-time, so even dynamic allocation is kind of static with the only difference - it will be done in the run time instead of the compilation time. In that case, if I am not going to free memory in the run-time, seemingly, I will not be exposed to the dynamic allocation dangers.
  3. I am not going to use absolute addressing, which immediately will take me into the static API

So, I am trying to think what would be the preferable FreeRTOS configuration for my project ? What are the specific risks , if any, with the dynamic allocation, given I will not delete objects on the fly ?

Since I am coming from the deep embedded systems applications with memory limitations, of course , I almost automatically decided to use static allocation, but some colleagues are coming from a different background and they like the fact that with dynamic allocation they have to take care for less parameters.

Some think that because originally FreeRTOS was designed with the Dynamic allocation, this option is more mature and reliable while working with FreeRTOS.

What do you think ?


Static vs Dynamic Configuration

Posted by rtel on January 10, 2019

What are the specific risks , if any, with the dynamic allocation, given I will not delete objects on the fly ?

If you allocate all your objects up front, and never delete them, then I would say there are no risks. If the allocation works the first time, and the configuration of your system doesn't change (same number of objects get allocated in the same order), then if all the objects are allocated the first time you switch your system on, then all the objects will get allocated every time you switch your system on (and in the absence of any other randomness on boot up - such as waiting for a network to connect - each object will use the same memory addresses each time too).

If you never free memory, then memory fragmentation is not going to happen, by definition.

Just with the information I have from your post, personally I would use dynamic allocation, it is just simpler and it sounds like in your case no reason not too.


Static vs Dynamic Configuration

Posted by richarddamon on January 11, 2019

Static Allocation has some small advantages. Generally a static allocation will be slightly smaller, as (except if using heap1 which can't free) a dynamic allocation will need to save a bit of extra information to allow for the memory to be deallocated, even if it never will.

Also, with Static Allocation, the memory is automatically allocated at link time, and there is no need to try to figure out how much memory is needed for the system, a preset that amount for the heap, thus you never need to worry that you didn't allocate enough, and the system hangs at startup on out of heap memory or allocate too much and have 'wasted' the space.

I personally tend to use FreeRTOS with a set of wrappers that take care of a number of the details, and they will automatically use the Static Allocations (if enabled) for most FreeRTOS objects. as I find them better to use.

The one case for dynamic allocation is if you do have a number of resources that there use comes and goes, and at different times you need different resources (or different sizes of resources) then dynamic allocation makes sense, but you then need to be careful to handle the out of memory condition


Static vs Dynamic Configuration

Posted by yevpator75 on January 12, 2019

Thank you Richard,

I personally tend to use FreeRTOS with a set of wrappers that take care of a number of the details, and they will automatically use the Static Allocations (if enabled) for most FreeRTOS objects. as I find them better to use.

Mind you to share a bit more about the wrappers? I am currious... What is their purpose? Could you give an example?


Static vs Dynamic Configuration

Posted by richarddamon on January 12, 2019

I have a set of lightweight C++ wrappers for FreeRTOS that I have mentioned on the forums a few times at: https://github.com/richard-damon/FreeRTOScpp

They will use Static Allocation if it is availavailabe and enough information has been provided to allow it (Tasks and Queue can include the stack/queue size as part of the object type or it can be a parameter for the constructor).

I find that using these classes helps me a lot in building FreeRTOS applications. I will note that in most cases my task/queues/semaphores etc are all defined as global objects and not created at 'run time' so static objects work well.


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


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

Latest News

FreeRTOS v10.2.0 is available for immediate download. MIT licensed, and including RISC-V and ARMv8-M (Cortex-M33) demos.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Mediatek

Renesas

RISC-V

SiFIve RISC-V

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