is better to open, write, close file than open, write, append, close?

is better to open, write, close file than open, write, append, close?

Post by Iulian Ile » Sat, 23 Dec 2006 00:45:14


Hello,
Let's say that I have a very big string to write into a file.

If I concatenate strings and write the string into file at the end of
processing than memory use will increase exponential. - BAD

If I open a file and instead concatenating strings I write it into a
file. At the end of processing I close the file. Ok, this works, memory
usage increases but not exponential.

Another method is to open a file, write string and close file. This
actions repeats until the end of script processing.

Which is best?

I hope you understood because my english is not very good.
 
 
 

is better to open, write, close file than open, write, append, close?

Post by pcx9 » Sat, 23 Dec 2006 01:32:36


Well Javascript, with a small exception for signed javascript code, has
no access to filesystems so this newsgroup is not the best place to ask.

That said, if I were writing a php program as you've described then I'd
just open the file to "a" (append) and add data as necessary. Reading
isn't really a problem since you can specify the size of the data you'd
like to read and read the "large" file in chunks, discarding sections
you no longer need.


--
http://www.yqcomputer.com/ -- Musings in Javascript, CSS.
$FA