Am I doing this right? (File byChunk)

Andrej Mitrovic andrej.mitrovich at gmail.com
Sun Sep 12 19:31:23 PDT 2010


I was refering to the open method, or when calling the constructor of
Text. But it doesn't actually *read* the contents until I ask it to
(which is a good thing). In other news it's late and I'm talking crazy
tonight, sorry. :)

On Mon, Sep 13, 2010 at 4:01 AM, Jonathan M Davis <jmdavisprog at gmail.com> wrote:
> 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