[Issue 1382] memory allocated for arrays in CTFE functions during compilation is not released

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jun 4 15:19:18 PDT 2010


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


bearophile_hugs at eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs at eml.cc


--- Comment #6 from bearophile_hugs at eml.cc 2010-06-04 15:19:11 PDT ---
A partially artificial test case. Faster and better versions are quite
possible, but I expect dmd to be able to run this quickly.


import std.stdio: writeln;

ubyte[1 << NPOW] setBits(int NPOW)() {
    nothrow pure uint setBits8(uint n) {
        uint result;
        foreach (i; 0 .. 8)
            if (n & (1 << i))
                result++;
        return result;
    }

    nothrow pure uint setBits16(uint n) {
        enum uint FIRST_UBYTE =  0b0000_0000_1111_1111;
        enum uint SECOND_UBYTE = 0b1111_1111_0000_0000;
        return setBits8(n & FIRST_UBYTE) + setBits8((n & SECOND_UBYTE) >> 8);
    }

    typeof(return) result;
    foreach (i; 1 .. result.length)
        result[i] = cast(typeof(result[0]))setBits16(i);
    return result;
}

enum nbits = setBits!16(); // currently 12 is about the max

void main() {
    writeln(nbits);
}

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