Reading a file eats whole memory

Emil Wojak emil at wojak.eu
Sun Oct 21 07:27:19 PDT 2007


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 std.stream;

int main(char [][] args) {
	Stream input=new File(args[0]);

	char[] data;
	input.read(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


More information about the Digitalmars-d-learn mailing list