Usage of memory by arrays

Adam D. Ruppe destructionator at gmail.com
Thu Apr 5 21:29:06 UTC 2018


On Thursday, 5 April 2018 at 20:58:32 UTC, unDEFER wrote:
> 100K * float[3] = 2356 Kbytes
>
> Why not 1200 Kbytes?

My guess is the reallocation triggered by ~= just passed the 
double threshold there.

When the runtime appends, it usually reserves (about) 2x of what 
it actually needs. This is a performance optimization in most 
cases because it cuts down on extra allocations, copies, and 
fragmentation.

But if you catch it right at the edge, after it doubles but 
before it is filled in by more loop, it can look like excess 
memory.


It is also possible that you are just seeing some fixed overhead 
with the process.


More information about the Digitalmars-d mailing list