create and initialise array

matheus matheus at gmail.com
Thu Jun 20 01:32:04 UTC 2019


On Thursday, 20 June 2019 at 01:06:09 UTC, Alex wrote:
> Is there a way of creating and initialising a dynamic array ?
>
> for example I am doing this:
>
> auto arr = new float[<big number>];
> arr[] = 0.0f;
>
> Profiling indicates that the compiler (gdc) is spending 
> significant time memsetting the whole array to something (nan 
> ?) before I immediately memset it to 0.0f.
>
> It would be good if there was a way of either void initialing 
> it so that the first memset is avoided or a way of replacing 
> the init value with a different one.
>
> Thanks,
> Alex

What about:

//DMD64 D Compiler 2.072.2

import std.stdio;
import std.array;

void main(){
     auto s = uninitializedArray!(float[])(100);
     s[] = 0.0f;
     writeln(s[0]);
}

Matheus.


More information about the Digitalmars-d-learn mailing list