[Issue 6421] New: Fixed size array literal assignment optimization

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jul 31 16:56:51 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=6421

           Summary: Fixed size array literal assignment optimization
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 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:

Don:

> 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
cases?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list