toys icon indicating copy to clipboard operation
toys copied to clipboard

Memory fragmentation issue (or not)

Open JoernEngel opened this issue 5 years ago • 1 comments

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.

JoernEngel avatar Feb 20 '19 15:02 JoernEngel

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.

WojciechMula avatar Apr 17 '20 17:04 WojciechMula