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

Discussion in 'Javascript' started by Iulian Ilea, Dec 21, 2006.

  1. Iulian Ilea

    Iulian Ilea Guest

    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.
    Iulian Ilea, Dec 21, 2006
    #1
    1. Advertising

  2. Iulian Ilea

    pcx99 Guest

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

    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
    pcx99, Dec 21, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Bencsik
    Replies:
    2
    Views:
    810
  2. HYRY
    Replies:
    10
    Views:
    582
    Bruno Desthuilliers
    Sep 26, 2007
  3. Jimmy
    Replies:
    3
    Views:
    311
    J. J. Farrell
    Sep 9, 2011
  4. Iñaki Baz Castillo
    Replies:
    7
    Views:
    817
    Iñaki Baz Castillo
    Jan 12, 2010
  5. Replies:
    2
    Views:
    42
    Mark H Harris
    May 13, 2014
Loading...

Share This Page