mikepurvis
mikepurvis

Reputation: 1638

How do I get available memory from lwIP's mem_malloc?

I'm using lwIP on an embedded device, and I feel that I may be running into some bugs related to running out of memory. I know that the mem_malloc function itself will return null when a memory allocation fails, but is there any way to get a rough assessment of the available memory at an arbitrary point in time? It would be great to be able to monitor it directly, to determine which usage patterns are leaking memory.

Thanks.

Upvotes: 5

Views: 4000

Answers (2)

Jona
Jona

Reputation: 1288

In LwIP version 2.1.3, You need to define MEM_STATS, but also LWIP_STATS. To output the stats, when you have defined LWIP_STATS_DISPLAY, you can use MEM_STATS_DISPLAY().

Upvotes: 2

Kyle Heironimus
Kyle Heironimus

Reputation: 8041

Define MEM_STATS and look at the memory statistics via stats_display_mem. See stats.h, stats.c, and opt.h among other places. That should get you started.

Upvotes: 6

Related Questions