2025-09-25 2:38 PM
On the STM32H753, I have configured ThreadX with static allocation. When doing a new and delete, where does the memory come from? As well, where does the memory come from when a, for example, std::vector is created on the stack and then increased in size with a concatenation?
Solved! Go to Solution.
2025-09-25 4:43 PM
The memory allocated by tx_byte_allocate is from a statically-allocated pool as it mentions in the note, not part of the heap. It dynamically allocates memory from a statically allocated pool. In that manner, you can always be assured that at least X bytes are available to allocate per thread.
New/delete (or malloc and free) come from the heap, which is typically after static allocation and before the stack.
> My linker file does not specify a heap location/size
You sure? It probably does. At least the location is probably specified, not the size. Look at the _sbrk implementation to see where it grabs memory from. Sometimes there's a check so it doesn't overflow the stack.
(You can edit your post with the down arrow menu at the top-right of your post.)
2025-09-25 2:54 PM - edited 2025-09-25 2:56 PM
Unless you use tx_byte_allocate to allocate the memory, it will come from the normal place. In this case, the heap for std::vectors.
I would argue this is not really static allocation, despite what they are calling it. It still comes from a pool and is assigned as needed at runtime. That's just the heap with extra steps.
2025-09-25 4:05 PM
Thanks TDK,
My linker file does not specify a heap location/size, so I'm sure from where this memory is coming and the max size? As well, I am able to use 'new' and 'delete', does this memory come from the same heap? I agree with your point about this configuration not being dynamic.
Gil
2025-09-25 4:07 PM
Correction: "I agree with your point about this memory configuration not being static.
2025-09-25 4:43 PM
The memory allocated by tx_byte_allocate is from a statically-allocated pool as it mentions in the note, not part of the heap. It dynamically allocates memory from a statically allocated pool. In that manner, you can always be assured that at least X bytes are available to allocate per thread.
New/delete (or malloc and free) come from the heap, which is typically after static allocation and before the stack.
> My linker file does not specify a heap location/size
You sure? It probably does. At least the location is probably specified, not the size. Look at the _sbrk implementation to see where it grabs memory from. Sometimes there's a check so it doesn't overflow the stack.
(You can edit your post with the down arrow menu at the top-right of your post.)