New vs length on dymamic array
Daniel Kozák
kozzi11 at gmail.com
Mon Nov 9 13:08:57 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;
In theory
auto array = new wchar[111]; // or new wchar[](111);
should do less work, but in practice I would guess there will be
almost zero difference in speed.
If you need to create new dynamic array with known size you
should prefere
auto array = new wchar[111]; // or new wchar[](111);
because it is make much more sense than create empty non
initialized array and then set it a length
More information about the Digitalmars-d-learn
mailing list