D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3370 - Compile-time global dynamic immutable arrays should NOT be constant-folded.
Summary: Compile-time global dynamic immutable arrays should NOT be constant-folded.
Status: RESOLVED DUPLICATE of issue 4298
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 critical
Assignee: No Owner
URL:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2009-10-06 15:04 UTC by David Simcha
Modified: 2015-06-09 01:29 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description David Simcha 2009-10-06 15:04:05 UTC
The following program runs out of memory b/c foo is apparently allocated and created every time through the loop:

import std.math, core.memory, std.stdio;

immutable real[] foo = [0,1,2,3,4];

void main() {
    GC.disable;

    foreach(i; 0..1_000_000_000) {
        auto bar = poly(i, foo);
    }
}

Changing the immutable to an enum results in the program still running out of memory.  

Removing all references to immutability fixes the problem.  

Changing the array to a static array fixes the problem.

Initializing the array inside main() fixes the problem.
Comment 1 David Simcha 2010-07-25 10:09:58 UTC
Marking as dup of bug 4298.  Although this report was filed first, 4298 is were all the discussion is, and it's a somewhat better bug report.

*** This issue has been marked as a duplicate of issue 4298 ***