Reading a file eats whole memory

div0 div0 at
Sun Oct 21 08:17:34 PDT 2007

Emil Wojak wrote:
> Hi!
> Could someone please explain why this code tries to eat my 1 GB memory 
> and gets killed by the kernel afterwards? Eventually it prints "Error: 
> Out of memory" when I set ulimit on memory prior to launching the program.
> The code:
> import;
> int main(char [][] args) {
>     Stream input=new File(args[0]);
>     char[] data;
>     input.close();
>     return 0;
> }
> My intention was to read the executable itself, which is about 444 kB.
> I'm running Linux, compiling with Digital Mars D Compiler v1.022

You are trying to read a string in, so I guess the routine is using the 
1st four bytes as a string length count. That's how tango works anyway IIRC.

My enormous talent is exceeded only by my outrageous laziness.

More information about the Digitalmars-d-learn mailing list