Skip to main content
Explorer II
September 25, 2025
Solved

ThreadX, using new and delete with no static allocation

  • September 25, 2025
  • 1 reply
  • 312 views

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?

    This topic has been closed for replies.
    Best answer by TDK

    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.)

    1 reply

    Super User
    September 25, 2025

    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.

    TDK_0-1758837059201.png

    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.

    Gil1Author
    Explorer II
    September 25, 2025

    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

    Gil1Author
    Explorer II
    September 25, 2025

    Correction: "I agree with your point about this memory configuration not being static.