C++ STM32H7 + TouchGFX + ThreadX + ESP32 MQTT - heap allocation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-02-16 12:05 AM
Hi, I'm working under not very restricted medical device with WiFi logging. This is quite a big project, requires processing of many string data so I want some easier tools. I know that in general it is not good to use heap on embedded, but H7 seems to have so much resources.
One part is communication with ESP32 - it has UART interface with custom JSON string protocol based on cJSON library. This library parses cstring to heap allocated structure, and in the same function free it. I added custom smart pointer wrapper to make it safer in deallocating.
To further secure messaging I use custom option wrapper (like optional in >= C++20) - agan move semantics.
Mostly I use std::strings to construct messages provided to ESP32, pass it between functions hoping that move semantics works.
I know what is heap segmentation.
And my questions:
- is move semantics with rule of zero works when compiling with -std=gnu++14?
- relatively short strings are processed on stack, is it true in embedded?
- can I use heap allocation for processing temporary strings without worry about segmentation?
- how can I check/profile dynamic memory in STM32CubeIDE to see if segmentation happens? Seems memory map shows only static memory.
Thank you for help :grinning_face:
- Labels:
-
STM32CubeIDE
-
STM32H7 Series
-
TouchGFX
-
UART-USART
-
Wifi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-02-19 11:49 AM
You probably mean fragmentation. When one allocates arbitrary sized blocks, nothing can save from fragmentation. On Cortex-A and desktop class PCs the virtual memory saves from the fragmentation of physical memory, but still it cannot solve the problem of a fragmentation of the virtual address space for a particular process. The only thing, which can solve the problem for specific cases, is using of a memory pools of equal-sized blocks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-02-24 1:01 AM
Hi, thank you for answer. I was searching for some information about memory pools, it seems it is not very popular topic. Do you have any resources how to use ThreadX's byte pools in dynamic allocation?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-02-26 11:51 AM
https://learn.microsoft.com/en-us/training/modules/threadx-memory-management/3-memory-management
Still byte pools have a fragmentation risk.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-02-26 2:57 PM
Memory management can be a real problem, as others have stated fragmentation eats up memory quick when you have various size allocation blocks.
Another way around this problem is using the size of the biggest block you need and use that as an allocation page. If the sizes are pretty close in size you will be OK if not you will waste a lot of memory.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-02-27 11:55 AM
And that brings us to the fixed-size block pools, which are also described in the link I gave.
