Advanced Users can post their questions and comments here for the not so Newbie crowd.

Moderator: eriksl

User avatar
By davydnorris
#88545
eriksl wrote:Yes, that has the drawback that it doesn't include the dynamic memory use of lwip (unless you configured lwip yourself to have everything static - I did).


In dev mode I call these in multiple places as my code runs so I can track the usage as it goes up and down - this seems to let me see dynamic allocation inside the networking libraries.

The other one I have used is system_show_malloc(), but this definitely is not for production - expect weird things to happen after you use it. It does give you a much more detailed view of your memory usage and segmentation.
User avatar
By Pablo2048
#88549
eriksl wrote:
Pablo2048 wrote:I use ESP.getHeapFragmentation(), ESP.getFreeHeap() and ESP.getMaxFreeBlockSize() to monitor the memory allocation. Also I'm doing (at least try to do...) all dynamic allocation at startup and avoid runtime dynamic heap allocation other than internal network buffers. It's not MISRA compliant, but it is close enough to allow 24/7 runtime for my application.

What development environment, this looks like Arduino?

Well, sort of - I'm using PIO & VSC as an development environment just because it perfectly suit my needs and I did not find any other comparable solution. I'm using PIO advanced scripting for patching linker script to add my special section inside flash map, I'm using advanced scripting to automatically get version info from git and define some variables from it. Then I use Arduino framework just to allow me to use some of the libraries (async web server, async mqtt, ...) so it simplifies my life. Rest is pure C/Cpp.
User avatar
By eriksl
#88551 I'd guess Arduino does it's own memory management (or at least a layer on top of the SDK code) and I also assume it will need some (dynamic) memory itself.

I work the other way around, I have eliminated all calls to malloc in my own code, I have configured LWIP to only use static pools of memory and also I have eliminated as much calls to SDK code as possible (and replaced it by own implementations or libc). Still some dynamic memory is used, probably in the WLAN handling code, but it's only ~500 bytes.

I never experiences issues that come down to memory leakage or temporary out of memory conditions.

Anyway, how did we come here: use of TLS. I think it needs a lot of memory. I now have ~7500 bytes free, which I got myself by painstakingly move ALL read-only data to flash, otherwise I wouldn't have any memory spare, even about 12 kilobytes short. So it's not possible to free up another few kb's just for TLS.

Having said that, newlib uses quite some space for temporary storage of non-reentrant threaded function calls ("impure data"). I have managed to get it down considerately, but it's still about 240 bytes. Anyone a idea how to get rid of it completely (see also other topic)?

Oh BTW, at 0x3fffe000 - 0x3fffeb2c, there seems to be quite a chunk of DRAM (NON-OS SDK) that's only used once during startup. I am using it for storing logging data. It might be used if you use more of the SDK functions than I do of course ;)