ESP8266 Developer Zone The Official ESP8266 Forum 2015-09-16T08:00:06+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=1110 2015-09-16T08:00:06+08:00 2015-09-16T08:00:06+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1110&p=3707#p3707 <![CDATA[Re: Meaning of value returned by system_get_free_heap_size]]> o allocating 256 bytes reduces the heap space by 272 bytes (16 bytes overhead)
o allocating 257 through 264 bytes reduces the heap space by 280 bytes (23 to 16 bytes overhead)
o allocating 265 through 272 bytes reduces the heap space by 288 bytes (23 to 16 bytes overhead)The conclusion that I draw from this data is that the allocation request is rounded up, if necessary, to be an integral multiple of 8 and then 16 bytes is added for tracking information.

I'm a bit surprised at this. I would have expected the request to be rounded up to an integral multiple of 4. Further, I expected to see at most 8 bytes of tracking overhead - 4 for the block size and 4 for a link to the next element in the list. I have written allocators that had overhead for only the block size (the "next element" link being stored in the data area of the freed block). Perhaps they're keeping all blocks, whether allocated or free, on a doubly linked list and storing the size, too.

Statistics: Posted by dkinzer — Wed Sep 16, 2015 8:00 am


]]>
2015-09-16T05:16:16+08:00 2015-09-16T05:16:16+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1110&p=3704#p3704 <![CDATA[Re: Meaning of value returned by system_get_free_heap_size]]>
    o initial free space (value returned by system_get_free_heap_size) is 47536
    o allocate 1000 bytes, free space is 46520 (apparently a 16-byte allocation overhead)
    o allocate 1000 bytes, free space is 45504
    o free the first 1000 byte allocation, free space is 46520 (but space is fragmented)
    o attempt to allocate 45620 fails
    o free the second 1000 byte allocate, free space is 47536
    o attempt to allocate 47536 bytes fails
    o attempt to allocate 47532 bytes fails
    o attempt to allocate 47528 bytes fails
    o attempt to allocate 47524 bytes fails
    o attempt to allocate 47520 bytes succeeds

Statistics: Posted by dkinzer — Wed Sep 16, 2015 5:16 am


]]>
2015-09-16T02:34:54+08:00 2015-09-16T02:34:54+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1110&p=3703#p3703 <![CDATA[Re: Meaning of value returned by system_get_free_heap_size]]>
Anyway, the function gives about 26 k free, which is about what I'd expect. If I add a variable of 1024k in size (not on the stack, but static), I can see the free heap space shrink to 25 k, so very predictable. Likewise with malloc.

Statistics: Posted by eriksl — Wed Sep 16, 2015 2:34 am


]]>
2015-09-16T01:05:17+08:00 2015-09-16T01:05:17+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1110&p=3701#p3701 <![CDATA[Meaning of value returned by system_get_free_heap_size]]>
Also, is there an API for walking the heap or for verifying the heap integrity?

Statistics: Posted by dkinzer — Wed Sep 16, 2015 1:05 am


]]>