473,396 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to get data in file before the end of long execution time

My C++ program made calculation several days and after electicity stop I lose all data. I try to print the data in intermediate files for every moment of interest and close these files with filename.close(); but all data continue to appear in the text file (in the windows explorer) after the end of the program or after I stop the execution. Obviously the data stay in some buffer and I don’t know how to visualize them before the end.
Thanks!
May 6 '10 #1

✓ answered by jkmyoung

Have you considered using different filenames? Eg
filename1.txt
filename2.txt
filename3.txt

I suggest having a timer somewhere in whatever loop you're using to output the data and switch files.
http://www.cplusplus.com/reference/clibrary/ctime/time/
so have something like:
Expand|Select|Wrap|Line Numbers
  1. time_t timerStart = time();
  2. and in the output loop:
  3. if (time() - timerStart > 3600){ // about every hour.
  4.   flush output stream.
  5.   close file.
  6.   rename file.
  7.   reopen new file at original location.
  8.   ...
  9.   timerStart = time(); // reset start time
  10. }
Just to clarify, you are doing the calculations manually, with human intervention? It's not fully automated, correct?

5 1624
jkmyoung
2,057 Expert 2GB
Please clarify:
"but all data continue to appear in the text file"

Did you want to edit the text file somehow?
How do you want to visualize the data?
How is the data written in the files?
May 7 '10 #2
Hi, jkmyoung, thanks for the attention.
How is the data written in the files?
ofstream filename;
filename.open("filename.txt", ios_base::out);
if (!filename) {cout<<" filename !open\n"; return 1;}
filename<< …<<"\n";
filename.close();
How do you want to visualize the data? – Numbers in text file.
Did you want to edit the text file somehow? Yes, I copy the numbers from the text file and analyze them in Excel.
All works fine but I can access the data after the end of the program or after I stop the execution and this is to long and I already lose data from several days calculation.

I find some solution but is ridiculous. I make the program to print useless data parallel with the needed, this fill this stupid buffer, which I don’t know where is, and the data appear in the file in the windows expoler before the end of the execution. I sort them in Excel and discard the junk.
Thanks again!
May 7 '10 #3
jkmyoung
2,057 Expert 2GB
Have you considered using different filenames? Eg
filename1.txt
filename2.txt
filename3.txt

I suggest having a timer somewhere in whatever loop you're using to output the data and switch files.
http://www.cplusplus.com/reference/clibrary/ctime/time/
so have something like:
Expand|Select|Wrap|Line Numbers
  1. time_t timerStart = time();
  2. and in the output loop:
  3. if (time() - timerStart > 3600){ // about every hour.
  4.   flush output stream.
  5.   close file.
  6.   rename file.
  7.   reopen new file at original location.
  8.   ...
  9.   timerStart = time(); // reset start time
  10. }
Just to clarify, you are doing the calculations manually, with human intervention? It's not fully automated, correct?
May 7 '10 #4
Yes, I use timer and multiples files for some cycles and logic to protect them form reopening, but I never used “flush output stream” and I think, that this is what I need. I don’t know how exactly to use “flush”, but I shall read in internet. Thanks man.
Yes, the calculations are not fully automated, i shall need more than 100 years if they are. I look in the data, use my intuition, change some coefficients and start again, but even like this i need weeks for one analysis and they are hundreds. I work on new metod for automatic speech recognition and after 12 years dashing my head against the wall, finaly I have good results. The human speech is terrible thing.
Thanks again!
May 7 '10 #5
It is simple “ filename<<flush; “ and it works. Thanks, jkmyoung! God bless you!
May 8 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Damien | last post by:
Hello to all, I've written a script that take quite a long time to execute (email sending). Last time I ran it, PHP gave me a "execution time limit exceeded" (or something like that), so I changed...
10
by: Doug | last post by:
I have a script that does a huge database update, which takes a long time. However, the host I am running on (and I suspect most hosts) are running in "safe mode." This means I cannot change the...
7
by: Adam | last post by:
Hi, I am working on a project that requires me to parse 52,005,167 rows in a MySQL table. I am using a series of PHP scripts for each test I would like to run on the data. For example I have...
6
by: Affan Syed | last post by:
Hi, I am getting this weird problem. I know what i am doing is strange.. i am using C++ vectors and fopen, but for some reason if i used ofstream in the similar scenario it would give me errors....
5
by: mas | last post by:
I have a Stored Procedure (SP) that creates the data required for a report that I show on a web page. The SP does all the work and just returns back a results set that I dump in an ASP.NET...
5
by: Johannes Lebek | last post by:
Hi there, lately, I experienced a strange thing on my DB2 V8.1 on Windows: Some queries took a very long time. A snapshot discovered the following: Number of executions = 47...
27
by: vishnu mahendra | last post by:
cah you please tell me how to find the execution time of a program in c. thank you in advance, vishnu
38
by: vashwath | last post by:
Might be off topic but I don't know where to post this question.Hope some body clears my doubt. The coding standard of the project which I am working on say's not to use malloc.When I asked my...
9
by: Shuan | last post by:
I am getting this error. Can it be fixed by setting more than 60 for the max_execution_time in php.in file? Fatal error: Maximum execution time of 60 seconds exceeded in categorycrawler.php on...
2
by: Richard | last post by:
Hello all, I am looking into issues with time-outs on a website. These appear to happen in a random way for some users. This is one example: Fatal error: Maximum execution time of 60 seconds...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
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...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.