Read content from a file, but skip RAM

BlitzMax Forums/BlitzMax Programming/Read content from a file, but skip RAM

SystemError51(Posted 2013) [#1]
Long time no see (:

Just a quick question. Would it somehow be possible to read content from a file directly, and not putting it into RAM?

Note: I know this would result in a performance hit which is quite possibly considerable.

I'm just wondering if something like this could be done at all. Let's say that for the moment, speed is not that important.

Thanks for your insights guys, as always.


// EDIT

Just to clarify. I want to read file contents all right. But I want to display its contents directly, and not storing it in the RAM.


Brucey(Posted 2013) [#2]
Where do you want to display its contents? Onto the console, or onto a Graphics display?

On console you could stream the data from file to standard out, for example - thereby not having the whole file loaded into memory.

However, to display text from a file onto a graphics display, you'll likely need to have all of the displayed text loaded into memory at any one time.


ImaginaryHuman(Posted 2013) [#3]
You can just open the file as a normal binary file and jump to where you want to read and read it a byte at a time if you want ... e.g. if you were trying to read some size or color information from a png image or something.


SystemError51(Posted 2013) [#4]
Brucey - ultimately the information (not text) ends up in a graphical display.

ImaginaryHuman - that may be something interesting to do. I will check that out and see if that suits my needs.


TaskMaster(Posted 2013) [#5]
What is the purpose? Anytime you read a portion of the file, it will "be in RAM"...


xlsior(Posted 2013) [#6]
Note that you don't need the -entire- file in RAM -- you can read one line at a time into the same string, do your thing, and overwrite the string by the next line in the file.

It's impossible to NEVER have it hit the RAM, though.


SystemError51(Posted 2013) [#7]
Yop... looks like I can't "skip" the RAM. I guess I will have to look into techniques to perform some kind of "smart load" which gets parts from I file I need at a particular point.


TaskMaster(Posted 2013) [#8]
Are you trying to read from a huge file or something?

You can seek to any portion of the file before you read. But that means you will have to know exactly where you want to go in the file, or you will have to seek around, read to see where you are, seek some more, etc until you find the right spot.


SystemError51(Posted 2013) [#9]
The files will potentially be pretty huge, yes. But I think I have an idea for that. I will test.


xlsior(Posted 2013) [#10]
Depending on just HOW huge: Keep in mind that by default there's a 2GB (?) file size limit, after that the built-in functions get confused. There is some code floating around on the forums that allows you to handle files larger than 2GB.