readLine

Niko Korhonen niktheblak at hotmail.com
Thu Apr 6 23:41:58 PDT 2006


BenHinkle wrote:
> Stream file = new BufferedFile("sample.txt");
> foreach(ulong n, char[] line; file) {
> stdout.writefln("line %d: %s",n,line);
> }
> file.close();
> the opApply for Stream uses a 128 bytes stack buffer and will only allocate a
> temporary buffer from the heap if a line is greater than 128. No memory
> allocations happen during that loop in the usual case.

...which also means that you have to .dup the variable 'line' if you 
plan to use it later. If you only pass a reference to 'line', it's 
contents will change at the next iteration.

-- 
Niko Korhonen
SW Developer



More information about the Digitalmars-d mailing list