473,666 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
1 2010
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1212
by: Amy G | last post by:
I am writing a simple Python program that will read in data from a database (userid, password, username). It will then store the data in a file in the format name:uid:gid:class:change:expire:gecos:home_dir:shell:password or in my case userid::20::::username::sh:password
13
3784
by: J. Campbell | last post by:
I'm wanting to output a text header file in front of the data portion of an output file. However when I use "\n" or "endl" as end of line, it just puts a 0x0a in the file(which is non-printing)...in Windows you need the (0x0d 0x0a) pair, if you want a new-line in a text editor. What's the correct way to get this 2-byte sequence into a file? Thanks #include <iostream>
1
4645
by: Doug Wyatt | last post by:
So I have a log file that I'm writing with one C# program and want to open and read it in another one. I open it via : StreamWriter log = File.AppendText(logPath); log.AutoFlush = true; but when I try to read it with another application, for instance, like : StreamReader log = new StreamReader(logPath); String logContents = log.ReadToEnd(); log.Close();
7
13176
by: Lumpierbritches | last post by:
Thank you in advance for any and all assistance. It is greatly appreciated. I would like a command button in VB.Net 2002 to open a text file, then to allow text from a textbox on the current form to be appended to that text file. Is there a place where I can see code to do this? I have the data/text on the clipboard using the clipboard class, now I want to append it to the text file either in Notepad or Wordpad. I have tried using the...
1
3596
by: piratelord | last post by:
I've an existing program I need to tweak that can open a non-text file at low level, find certain strings and replace with another, and write back to a new file. The string replacement bit isn't a problem as that already works, the trouble is reading the file and writing it back. At the moment, I'm just trying to read it, and write it back and check the file is exactly the same as originial. Code is below, but the problems I'm...
5
11207
by: Ryan Liu | last post by:
Hi, Both way works, I'd just ask some experts which way is better? My application creates a log file daily. Now each time when I write a log, I will open the file and append to the end. Ocz, if the file is not exist(e.g. another day), it will creates the file first.
9
4987
by: Robin | last post by:
// Pls note that test.txt exists. #include <iostream> #include <fstream> #include <string> using namespace std; int main() { fstream fs("test.txt", ios_base::in | ios_base::app);
4
7878
by: varsha desai | last post by:
Hello there, I want to change some data(which is in one line only) of text file using VB 6.0. Which is the best method for it? Another question is I want to delete last two, three lines of text file using VB 6.0. Which method can be best method for it?
4
1068
by: Ben | last post by:
Hello All: I am new to Python, and I love it!! I am running 2.6 on Windows. I have a flat text file here is an example of 3 lines with numbers changed for security: 999999999088869199999999990200810999999 999999999088869199999999990200810999999 999999999088869199999999990200810999999
0
8443
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8866
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7385
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.