why does malloc not give memory that is available?

marcmerlin
Posts: 16
Joined: Mon Apr 17, 2017 12:50 am

why does malloc not give memory that is available?

Postby marcmerlin » Sun Dec 01, 2019 1:12 am

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?

chegewara
Posts: 1234
Joined: Wed Jun 14, 2017 9:00 pm

Re: why does malloc not give memory that is available?

Postby chegewara » Sun Dec 01, 2019 2:26 am

:oops: :oops:
Last edited by chegewara on Sun Dec 01, 2019 7:05 am, edited 1 time in total.

marcmerlin
Posts: 16
Joined: Mon Apr 17, 2017 12:50 am

Re: why does malloc not give memory that is available?

Postby marcmerlin » Sun Dec 01, 2019 4:37 am

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.

Who is online

Users browsing this forum: Markus and 26 guests