www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6421] New: Fixed size array literal assignment optimization

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: bearophile_hugs eml.cc



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: -------
Jul 31 2011
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6421




This bug is related to bug 2356, the difference is this enhancement request
asks for a language definition change too.

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