Closed ApiumJacob closed 10 months ago
@Xasin - that is incorrect; IIRC sbrk requests are normally large blocks, not related to actual amount used. If this was trivial I would have already done it.
I spent 30-40 minutes trying to implement this, I found it was not a 30-40 minute task so created this issue.
Alright, then I am sorry for my interjection. I'm still fairly new to this and my initial naive assumption was that malloc or assorted functions use sbrk to fetch a larger memory area to use for allocations, but only use it when they need to expand the area they have and only by the necessary amount.
Then I will watch this thread with interest ^^
My next assumption would have been that one can monitor the amount of memory allocated by malloc and free calls to get a naive high watermark that ignores fragmentation, but I'm guessing the thing we optimally want is the smallest 'largest free block size' that one could allocate...
Shame that the newlib library doesn't seem to do that.
Will not be implemented for reasons discussed above...
I second this, would be very nice to have and should be easy enough to implement by just adding a small check to the _sbrk_r, right?
Maybe I could try making a quick PR to add this.
Heck, with a bit of tweaking and using the FreeRTOS Task Switch hook or something similar one could even implement per-task heap use tracking, but that is probably a bit more than necessary for now :P
I was tempted to use mallinfo(), but checking newlib's documentation they say the "allocation high watermark is unused". What a shame, it's a useful metric to have.