filename.writeln() across network

Paul phshaffer at gmail.com
Tue Jun 26 05:20:35 PDT 2012


On Thursday, 21 June 2012 at 19:52:26 UTC, Danny Arends wrote:
> 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..

Thanks for the idea.  I thought maybe there would be a way to use 
writeln() to do what you illustrated...basically writing to a 
buffer and then write the buffer to disk when needed.  It would 
be a nice feature that would allow a developer to change the 
character of his file writing quickly w/o changing much code.  
Maybe open a file File("filemane.txt", "buffer") or 
somesuch...and then a way to tell it to write to disk when you 
want.


More information about the Digitalmars-d-learn mailing list