Am I doing this right? (File byChunk)

Jonathan M Davis jmdavisprog at gmail.com
Sun Sep 12 19:01:46 PDT 2010


On Sunday 12 September 2010 18:04:14 Andrej Mitrovic wrote:
> Here's a little snippet of code that interfaces with Scintilla (it works
> btw.):
> 
> File file = File("test.txt", "r");
> foreach (ubyte[] buf; file.byChunk(4096))
> {
> 	sendEditor(SCI_ADDTEXT, buf.length, (cast(char[])buf).idup);
> }
> 
> The cast looks ugly, but I *have* to send a copy. Am I doing it right, or
> can I make this a bit simpler? Otherwise I can use file.byLine, but I
> think this would be much slower (unless D reads the entire contents at
> once into memory, but I think it does not).

I'd have to check, but I believe that byLine() reads the whole line into memory 
but not the whole file.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list