readLine

BenHinkle BenHinkle_member at pathlink.com
Wed Apr 5 06:39:55 PDT 2006


In article <e0up1s$2e3j$1 at digitaldaemon.com>, nilesr at rodsnet.com says...
>
>I am new to D and have been reading documentation. I had a couple question about
>the readLine function. After looking through some of the archive posts I had
>seen there were some performance issues using this function, have those been
>corrected in the current version?
>If not does anyone have any suggestion on how to parse a large file by line, or
>better yet with specific character rather than just \n? This is for part of a
>larger project I am looking to use D for or I would use perl or something to do
>it.
>
>Thanks,
>Chris
>
>

Please post any performance issues you find. I'd guess the posts you refer to
either use unbuffered streams or do not pass a scratch buffer to readLine. I
recommend using the example from the doc as a model
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.

-Ben





More information about the Digitalmars-d mailing list