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

I

Iulian Ilea

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.
 
P

pcx99

Iulian said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top