Page 1 of 1

Array for memory allocation in FreeRtos

Posted: Wed Sep 10, 2025 6:34 pm
by Dario Lobos
I am new in this and I want to start to use FreeRtos. I seen that statically memory allocation is done by an array and depth is in bytes and not words. But array is of type StackType_t

Example says:

#define STACK_SIZE 200

...
// Buffer that the task being created will use as its stack. Note this is
// an array of StackType_t variables. The size of StackType_t is dependent on
// the RTOS port.

StackType_t xStack[ STACK_SIZE ];

So depends on port in this case Esp32.

Index of the array and depth are both in bytes. I am asking if it have to be

ARRAY_INDEX = STACK SIZE / sizeof(* StackType_t)

Or if size Stacktype_t = 1 byte.

Many thanks in advance for your comments.

Re: Array for memory allocation in FreeRtos

Posted: Thu Sep 11, 2025 8:40 am
by MicroController
Yes, stack_size_bytes = stack_depth * sizeof( StackType_t ) and stack_depth = stack_size_bytes / sizeof( StackType_t ).

So you'd usually

Code: Select all

#define STACK_SIZE (4*1024) // 4kB

StackType_t the_stack[ STACK_SIZE / sizeof( StackType_t ) ];
But with the ESP-IDF it doesn't really matter because sizeof( StackType_t ) == 1.