why does malloc not give memory that is available?
Posted: Sun Dec 01, 2019 1:12 am
by marcmerlin
Code: Select all
printf("Heap/32-bit Memory Available: %6d bytes total, %6d bytes largest free block\n", heap_caps_get_free_size(0), heap_caps_get_largest_free_block(0));
uint32_t mallocsize = m_absMWidth * m_absBWidth * m_absMHeight * m_absBHeight * sizeof(CRGB);
p_LED = (struct CRGB *) malloc(mallocsize);
if (! p_LED) { Serial.print("Malloc LEDMatrix Failed. Bytes requested: "); Serial.println(mallocsize);}
returns
Code: Select all
Heap/32-bit Memory Available: 136444 bytes total, 82808 bytes largest free block
Malloc LEDMatrix Failed. Bytes requested: 49152
I'm confused, why?
Re: why does malloc not give memory that is available?
Posted: Sun Dec 01, 2019 2:26 am
by chegewara
Re: why does malloc not give memory that is available?
Posted: Sun Dec 01, 2019 4:37 am
by marcmerlin
Turns out I had to print 8bit memory, I forgot about that.
Heap/32-bit Memory Available: 139756 bytes total, 82808 bytes largest free block
8-bit/DMA Memory Available : 56804 bytes total, 43520 bytes largest free block
Malloc LEDMatrix Failed. Bytes requested: 49152
So, this explains that. Sad that ESP32 memory is hard to deal with/fragmented. I have 140KB free, but most of that memory is 32bit only, so I can't use it for a regular malloc.