hi,

i got an 'out of memory' error when compiling lage(r) d files
using dmd v1.061 on windows.
on freebsd/linux the same dmd version compiles the d source without problems.

interesting is that i get the same error when compiling a similar c source
code using the digital mars c compiler.

anyone knows which wall i'm hitting in the dmd/dmc compiler backend ?

the source files in question are generated using the following d program
(mkdata.d) from binary blobs (e.g. zip files) :

howto reproduce :
dmd mkdata
mkdata foo.zip > data.d
dmd -c data.d

for dmc:
mkdata -cxx foo.zip > data.c
dmc -c data.c

the problem starts when foo.zip is larger than 800kb giving a 4+ mb data.d

-------------- mkdata.d ----------------------------------------------
import std.stdio;
import std.string;
import std.file;
import std.path;

static void gen_d(string name,string data)
{
        writefln("const string name_" ~ name ~ "=\"" ~ name ~ "\";");
        writef("const ubyte[] data_" ~ name ~ " = [");
        foreach(n,d;data)
                writef("0x%02x,",d);
        writefln("\n]; // end of data_" ~ name);
}

static void gen_cxx(string name,string data)
{
        writefln("#ifndef " ~ std.string.toupper(name) ~ "_h");
        writefln("#define " ~ std.string.toupper(name) ~ "_h");

        writefln("static const char* name_" ~ name ~ "=\"" ~ name ~ "\";");
        writefln("static unsigned int size_" ~ name ~ "=%d;",data.length);
        writef("static const char data_" ~ name ~ "[] = {");

        foreach(n,d;data)
        {
                if( (n % 16) == 0)
                        writef("\n// %d : 0x%04x\n",n/16,n);
                writef("0x%02x,",d);
        }
        writefln("\n}; // end of data_" ~ name);
        writefln("\n#endif // " ~ std.string.toupper(name) ~ "_h");
}

int main(string[] args)
{
        bool do_cxx=false;
        uint n=0;
        foreach(arg;args[1 .. $])
        {
                if(arg == "-cxx")
                {
                        do_cxx=true;
                        continue;
                }

                if(n == 0 && !do_cxx) writefln("module ddata;\n");

                string name=arg;
                name=replace(name,"-","_");
                name=replace(name,".","_");

                try
                {
                        char[] data=cast(char[]) std.file.read(arg);
                        n++;
                        string tag=format("%s%d",name,n);

                        do_cxx ? gen_cxx(name,data) : gen_d(name,data);
                }
                catch(FileException ex)
                {
                        writefln(arg ~ " : got FileEx: " ~ ex.msg);
                        continue ; //next;
                }
        }

        return 0;
}

Reply via email to