create and initialise array

KnightMare black80 at bk.ru
Thu Jun 20 07:57:25 UTC 2019


On Thursday, 20 June 2019 at 01:32:04 UTC, matheus wrote:
>>
> import std.stdio;
> import std.array;
>
> void main(){
>     auto s = uninitializedArray!(float[])(100);
>     s[] = 0.0f;
>     writeln(s[0]);
> }
>

another version:
auto arr = new double[ 10 ];
writeln( arr[5] ); // NaN
arr.length += 10;
writeln( arr[15] ); // NaN

imo NaN is useless, weird and unusual coz integrals and pointers 
are "all bits zeroes" but float and chars are "all bits ones". 
WTF? its strange that bool.init is false in such case.
.init = "all zeroes" can be faster initialize any block of memory.
for example array of structs coz u dont need copy struct.init to 
each element and just fill memory with AVX2 zeroed register (or 
another fastest hack).
with "all zeroes" u can continue work without reinitialization 
first as arr[15] += 3.14;
probably should be added option to compiler. and again module 
behavior will be different due to this option. NaN/#FF was worst 
decision. The road to hell is paved with good intentions.
or do a poll for the last decision for several months and leave 
it as it is forever or recompile new versions with zeros.
and of course there must be the possibility of increasing the 
length of the array with a given value.


More information about the Digitalmars-d-learn mailing list