October 18, 2016 Re: inferred size for static array initialization | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On 10/18/16 6:35 AM, Nordlöw wrote:
> On Monday, 2 May 2016 at 17:43:56 UTC, Namespace wrote:
>> immutable auto a = [1,2,3].s;
>
> Will that have zero run-time overhead compared to:
>
> immutable int[3] a = [1,2,3];
Neither will have zero runtime overhead, but use the disassembler to see if there is a difference. My understanding is that while the compiler used to allocate whenever it saw an array literal (including your above usage), that is no longer the case.
-Steve
|
October 18, 2016 Re: inferred size for static array initialization | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Tuesday, 18 October 2016 at 10:35:44 UTC, Nordlöw wrote: > On Monday, 2 May 2016 at 17:43:56 UTC, Namespace wrote: >> immutable auto a = [1,2,3].s; > > Will that have zero run-time overhead compared to: > > immutable int[3] a = [1,2,3]; > > ? I'm not quite sure if pragma(inline, true) would result in zero runtime overhead, but without you have 3 lines of assembler more (with gdc). https://godbolt.org/g/JUjP1d https://godbolt.org/g/qaqylp |
Copyright © 1999-2021 by the D Language Foundation