WojciechMula / toys

Storage for my snippets, toy programs, etc.
BSD 2-Clause "Simplified" License
316 stars 38 forks source link

Memory fragmentation issue (or not) #11

Open JoernEngel opened 5 years ago

JoernEngel commented 5 years ago

If you are measuring allocator overhead for tiny allocations like 1 byte, I'd argue that you should add the cost of a pointer to the overhead. That cost is paid by the application, not by the memory allocator. But an 8-byte pointer for a 1-byte allocation is imo too much to just ignore. Allocator overhead is 16 bytes plus padding (to a multiple of 16 bytes), so the pointer adds between 25% and 50% to the overhead you measured.

It's a matter of opinion and you may well disagree. But I thought I should mention it.

WojciechMula commented 4 years ago

Thank you for this comment. You are right, we seldom allocate memory and do not store the pointer. :) But: a pointer can be static, can be located on a stack or can be a part of larger array dynamically allocated (so fragmentation is for larger block).

What I measured is sole cost of allocation, didn't take any real-world scenario.