3 ms·
A bigger saving is in the allocation metadata. Every time you allocate something on the heap, you also need to save information about the size, maybe some flags
by viraptor 7y ago
A bigger saving is in the allocation metadata. Every time you allocate something on the heap, you also need to save information about the size, maybe some flags and padding to align on a page. And if the entries are small, you also get better cache locality.
Putting things in an array works around all of that (unless you need to handle tombstones)
- Dylan16807 7y agoA reasonable allocator should already be grouping allocations of similar size together. In a whole lot of cases this means your metadata is no more than a single byte per object, and the padding is no more than you'd have inside an array.
- viraptor 7y agoTrue, it really depends on the allocator.