More on C++ stack arrays
Iain Buclaw
ibuclaw at ubuntu.com
Mon Oct 21 14:41:16 PDT 2013
On 21 October 2013 22:24, David Nadlinger <code at klickverbot.at> wrote:
> On Monday, 21 October 2013 at 21:07:46 UTC, Iain Buclaw wrote:
>>
>> But yes. I think a GC memcopy should be occuring, as dynamic arrays
>> aren't passed by value, so are expected to last the lifetime of the
>> reference to the address.
>
>
> This doesn't produce a heap copy (neither according to the spec nor to
> actual DMD/LDC behaviour):
>
> ---
> void foo() {
> int[3] a;
> int[] b = a;
> }
> ---
>
> Thus, your example will not copy any data either, as due to associativity,
> it is equivalent to an assignment to y followed by an assignment of y to x.
> x simply is a slice of the stack-allocated static array.
>
I know this, but it does deter me against changing gdc over to stack
allocating array literals. :-)
I'll mull on it over night.
--
Iain Buclaw
*(p < e ? p++ : p) = (c & 0x0f) + '0';
More information about the Digitalmars-d
mailing list