Summary: Fixed size array literal assignment optimization
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD

--- Comment #0 from 2011-07-31 16:56:49 PDT ---
>From a comment by Peter Alexander:

> int[3] a = [1, 2, 3]; // in D, this allocates then copies
> int a[3] = {1, 2, 3}; // in C++, this doesn't allocate
> Apparently, to avoid the allocation in D, you must do:
> static const int[3] staticA = [1, 2, 3]; // in data segment
> int[3] a = staticA; // non-allocating copy
> These little 'behind your back' allocations are good examples of my previous 
> two points.

Memory allocations caused by this, inside an inner loop, have given me
performance troubles.
I suggest to add an optimization to the DMD front-end to avoid this problem.

Some comments received:


> Yeah, it's not fundamental, and not even very complicated. The current
> implementation was a quick hack to provide the functionality, that
> hasn't been replaced with a proper implementation yet. All that's
> required to fix it is a bit of code in e2ir.c.

Peter Alexander:

> Also, I think it
> would be worth while adding it to the language definition so that it's
> not merely an implementation detail.

Timon Gehr:

> I think it should be more than an implementation detail, as it can severely 
> affect
> performance.

How do you specify this in the D language definition? What are the corner

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to