Thread overview
Re: new array without auto-initialization
Sep 26, 2013
H. S. Teoh
Sep 26, 2013
Matej Nanut
Sep 26, 2013
Matej Nanut
September 26, 2013
On Thu, Sep 26, 2013 at 11:23:10PM +0200, Joseph Rushton Wakeling wrote:
> Hello all,
> 
> Suppose I create a new dynamic array:
> 
>     auto arr = new int[10];
> 
> If I recall right, the values inside arr will be auto-initialized to
> int.init (which is 0).
> 
> Again, if I recall right, there's a simple way to increase performance by not auto-initializing the values, but I can't remember what it is.
[...]

You mean:

	int[10] arr = void;

?


T

-- 
He who laughs last thinks slowest.
September 26, 2013
On 26/09/13 23:23, H. S. Teoh wrote:
> You mean:
>
> 	int[10] arr = void;

It's what I was thinking of, but does that also work with a dynamic array declaration?

    int[] arr = new int[n];
September 26, 2013
On Thursday, 26 September 2013 at 22:14:27 UTC, Joseph Rushton Wakeling wrote:
> It's what I was thinking of, but does that also work with a dynamic array declaration?
>
>     int[] arr = new int[n];

Check out std.array.uninitializedArray.

Matej
September 26, 2013
On Thursday, 26 September 2013 at 22:21:58 UTC, Matej Nanut wrote:
> On Thursday, 26 September 2013 at 22:14:27 UTC, Joseph Rushton Wakeling wrote:
>> It's what I was thinking of, but does that also work with a dynamic array declaration?
>>
>>    int[] arr = new int[n];
>
> Check out std.array.uninitializedArray.
>
> Matej

Bah, I just noticed you already mentioned that, but the threading got messed up for me so I didn't see it on the page. Sorry!

Anyway, I don't think there is another way to do it.