New vs length on dymamic array
user1234
user1234 at 12.de
Mon Nov 9 13:17:17 UTC 2020
On Monday, 9 November 2020 at 08:06:54 UTC, Andrey wrote:
> Hello,
>
> Are here any differences in creation of dynamic array with
> known size?
>
>> auto array = new wchar[](111);
>
> and
>
>> wchar[] array;
>> array.length = 111;
It's the same. If the two are valid then you are in a function.
So it's an alloca for the dynamic array payload (8+8 bytes on
x86_64) then a LengthExpression that will lead to a GC.malloc,
and finally a memset for all the elements default values.
More information about the Digitalmars-d-learn
mailing list