Array for memory allocation in FreeRtos

Dario Lobos
Posts: 8
Joined: Wed Sep 10, 2025 6:24 pm

Array for memory allocation in FreeRtos

Postby Dario Lobos » Wed Sep 10, 2025 6:34 pm

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.

MicroController
Posts: 2663
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Array for memory allocation in FreeRtos

Postby MicroController » Thu Sep 11, 2025 8:40 am

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.

Who is online

Users browsing this forum: meta-externalagent, PetalBot and 5 guests