[Issue 6445] New: [CTFE] Absurd memory usage (still) on building array
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Sat Aug  6 13:34:13 PDT 2011
    
    
  
http://d.puremagic.com/issues/show_bug.cgi?id=6445
           Summary: [CTFE] Absurd memory usage (still) on building array
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: performance
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: dsimcha at yahoo.com
--- Comment #0 from David Simcha <dsimcha at yahoo.com> 2011-08-06 13:34:11 PDT ---
The following program uses over a gigabyte of memory at compile time.  I
thought these kinds of issues were fixed by the rewrite of CTFE in the last
release.
enum staticFacTableLen = 1000;
immutable table = makeLogFacTable();
immutable(double[staticFacTableLen]) makeLogFacTable() pure nothrow {
    static real log(real x) pure nothrow @safe
    {
        immutable xMinusPlus = (x - 1) / (x + 1);
        immutable xMinusPlusSquared = xMinusPlus * xMinusPlus;
        real xMinusPlusPow = xMinusPlus * xMinusPlusSquared;
        real ret = xMinusPlus;
        real power = 3;
        while(true)
        {
            immutable toAdd = xMinusPlusPow / power;
            immutable oldRet = ret;
            ret += toAdd;
            if(ret == oldRet || ret != ret)
            {
                return 2 * ret;
            }
            power += 2;
            xMinusPlusPow *= xMinusPlusSquared;
        }
        assert(0);
    }
    double[staticFacTableLen] ret;
    ret[0] = 0;
    foreach(i; 1..staticFacTableLen) {
        ret[i] = ret[i - 1] + log(i);
    }
    return cast(immutable) ret;
}
-- 
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