Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Need help with Reading data from file.

Author
Message
Checker
20
Years of Service
User Offline
Joined: 23rd Feb 2004
Location:
Posted: 27th Feb 2004 21:31
I'm trying to read numerical data from a file. The code is attached. It either bombs without printing anything or it never comes back.

I make a few simple changes by removing the "for loop" and putting the read code in a "do loop" with a few other small changes and it works as I expect. See attached code.

What's wrong with the "for loop" code? What am I missing here? The data file is reasonably large, about 230,000 values, all on separate lines with the first line having the number of values in the file.
AciDucK
21
Years of Service
User Offline
Joined: 13th Aug 2003
Location:
Posted: 28th Feb 2004 15:44
Your problem is the line "i = i+1" in the FOR loop. The FOR loop increase this value automatically. You don't need to change it, and when you change it the loop doesn't work properly. Just delete this line and it will work fine.
Checker
20
Years of Service
User Offline
Joined: 23rd Feb 2004
Location:
Posted: 4th Mar 2004 21:49
I feel so stupid!

Quote: "Your problem is the line "i = i+1" in the FOR loop. "


You are quite right that this was a problem but only because I cut and pasted a section of code that I was starting to modify to try something different. The actual code I used did not have the offending line.

What appears to be happening is that Darkbasic is buffering the print output until the double "for loop" has completed before it prints the data. For large input data files this can take some time and evidently I'm not the patient type. For really large files there's probably some cache thrashing going on too which can make things even worse.

The whole purpose for putting the print in a loop like this is a quick and temporary check that data as it was being read in correctly. Sometimes this can be handy for debugging.

It's interesting to note that Darkbasic does not "substantially" buffer print output in a "do...loop".

Has anyone else noticed this phenomenon? Is there a way to turn of the output buffering?

Login to post a reply

Server time is: 2024-11-26 07:24:55
Your offset time is: 2024-11-26 07:24:55