Optimize my code =)

Xinok xinok at live.com
Fri Feb 14 10:13:00 PST 2014


On Friday, 14 February 2014 at 16:56:29 UTC, bearophile wrote:
> Craig Dillabaugh:
>
>>> 	this.data = new T[this.dim.size];
>>
>> with:
>>
>> this.data.length = this.dim.size
>
> It's the same thing.
>
> Bye,
> bearophile

Not quite. Setting length will copy over the existing contents of 
the array. Using new simply sets every element to .init.

Granted, this.data is empty meaning there's nothing to copy over, 
so there's a negligible overhead which may be optimized out by 
the compiler anyways.

There's also the uninitializedArray function:
http://dlang.org/phobos/std_array.html#.uninitializedArray


More information about the Digitalmars-d-learn mailing list