filename.writeln() across network
Danny Arends
Danny.Arends at gmail.com
Thu Jun 21 12:52:25 PDT 2012
On Thursday, 21 June 2012 at 17:14:34 UTC, Regan Heath wrote:
> On Thu, 21 Jun 2012 14:56:37 +0100, Paul <phshaffer at gmail.com>
> wrote:
>
>> I wrote a program that parses a text file and writes results
>> as it is processing the file (i.e. many writeln()'s). On my
>> local harddrive it works fine. When I later used it on a file
>> located on a file server, it went from 500ms to 1 minute
>> processing time.
>>
>> It there a more efficient way to write out the results that
>> would say maybe only access the harddrive as it closes the
>> connection...or somesuch?
>>
>> Thanks for your assistance.
>
> I imagine writeln is synchronous/non-overlapped IO. Meaning,
> the call to writeln doesn't return until the write has
> "completed". So, on every call you're basically waiting for
> the network IO to complete before you process something else
> locally.
Isn't the most simple approach then to build up the whole file in
memory as a single string, using \n and then do a single write
across the network ?
like:
void main(string args[]){
string filecontent = "";
filecontent ~= "#include std.stdio\n";
filecontent ~= "int x = " ~ x ~ ";\n";
//etc etc...
auto f = new File("X:\\MyNetworkDir\\file.txt");
f.writeln(filecontent);
f.close();
}
Haven't tested the code, but if network IO is the wait, then just
increase the buffer..
More information about the Digitalmars-d-learn
mailing list