Bug 4236 – 'out of memory' error compiling on windows
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-05-26T12:31:11Z
Last change time
2023-01-06T12:29:00Z
Keywords
ice
Assigned to
No Owner
Creator
Walter Bright
Comments
Comment #0 by bugzilla — 2010-05-26T12:31:11Z
Reported by [email protected]:
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;
}
Comment #1 by razvan.nitu1305 — 2021-03-17T14:13:12Z
Is this issue still valid?
Comment #2 by Bastiaan — 2023-01-06T12:29:00Z
No, this is no longer an issue.
Tested with v2.099.1 on Windows 10.
dmd mkdata.d
mkdata.exe > data.d
dmd -c data.d
-------------- mkdata.d ----------------------------------------------
import std.stdio, std.conv;
void main()
{
writeln("module data;\n");
write("const ubyte[] blob = [0");
foreach (i; 1 .. 8_000_000)
write(", ", (i % ubyte.max).to!string);
writeln("];\n");
}