A faster way to read Files?

BlitzMax Forums/BlitzMax Beginners Area/A faster way to read Files?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.


Local file=OpenFile(GeoDatpath$)
While Not Eof(file)
LineofData$=ReadLine(file)
Wend
CloseStream File



Each time the Readline command is executed, it reads a line from your datafile, puts that line in a string-object and assigns the pointer of that string-object (it's memory-address) to the variable LineofData$, overwriting the previous memory-location.

So eventually you'll end up using megabytes of memory, because BMax creates a new string each loop, without deleting/overwriting the old one.
The previous line still exists in memory, but the LineofData$ variable is pointing to the new string, leaving the old one in memory, without a reference to it.

That's why FlushMem fixes it, it deletes any object (including string-objects) that doesn't have a reference to it.

Hope this all makes sense (and that it is correct).