auto arr = [1, 2, 3] should be a static array, not a GC allocated array
Era Scarecrow
rtcvb32 at yahoo.com
Sat Jul 16 21:51:40 UTC 2022
On Thursday, 14 July 2022 at 13:14:59 UTC, ryuukk_ wrote:
> It is misleading, nobody expect this to be GC allocated
>
> It should be equal to:
>
> ```D
> int[3] arr = [1, 2, 3]
> ```
>
> Also why it is GC allocated without requiring ``new``?
That would be a little confusing. If i were writing a language or
compiler; if it was a slice/array without a known length it would
allocate, if it is a known length or on the stack it would copy
to the stack from a fixed immutable array in ROM, and in the case
it's immutable it would just point to the array it would have
copied from.
i know enum array values would likely always be forcibly
allocated either way.
And static/module immutable items could point to the original
ROM data as it would be allocated during compile-time.
More information about the Digitalmars-d
mailing list