new Type[count] takes too much?

safety0ff safety0ff.dev at gmail.com
Thu Oct 31 02:48:22 PDT 2013


On Thursday, 31 October 2013 at 09:15:53 UTC, Namespace wrote:
> I'm sure we had already this conversation but I don't find the 
> thread.
>
> T[] buffer = new T[N]; assumes more space than stated (in 
> average 2010 elements more. See: 
> http://dpaste.dzfl.pl/af92ad22c). It behaves exactly like 
> reserve and that is IMO wrong. If I reserve memory with 
> buffer.reserve(N), I want to have at least N elements. That 
> behaviour is correct. But if I use new T[N] I mostly want 
> exactly N elements and no extra space.
>
> Thoughts?

To me it looks like it is derived directly from the way the GC 
allocates chunks:
Next power of two if less than 4096 otherwise some multiple of 
4096.

Unless you modify the GC, this behaviour is present whether you 
can see it or not (http://dpaste.dzfl.pl/5481ffc2 .)


More information about the Digitalmars-d-learn mailing list