By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,496 Members | 1,266 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,496 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.

Dec 21 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Iulian Ilea wrote:
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.

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.hunlock.com -- Musings in Javascript, CSS.
$FA
Dec 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.