pavel-kirienko / o1heap

Constant-complexity deterministic memory allocator (heap) for hard real-time high-integrity embedded systems. There is very little activity because the project is finished and does not require further changes.
MIT License
245 stars 26 forks source link

O1HeapDiagnostics peak alloc > peak requested, is this expected behaviour? #3

Closed PetervdPerk-NXP closed 3 years ago

PetervdPerk-NXP commented 3 years ago

I've implemented a status message in my application to keep track of the O1Heap I'm using but I've noticed that the diagnostics function reports that peak_allocated is greater then peak_request_size.

INFO [uavcan_v1] Heap status 64/8000 Peak alloc 896 Peak req 256 OOM count 0

I would've expected them to be equal or that peak_request_size would be greater then peak_allocated. Is there a technical reason why this occurs?

pavel-kirienko commented 3 years ago

If you look at the description of peak_request_size, it says: "not including the rounding and the allocator's own per-fragment overhead, so the total is larger". But the docs for allocated say: "including the per-fragment overhead and size alignment. For example, if the application requested a fragment of size 1 byte, the value reported here may be 32 bytes."

When you request, say, 200 bytes of memory, the allocator gives you 256 - O1HEAP_ALIGNMENT bytes. This extra memory is included in the peak_allocated but not peak_request_size.