Hi folks,
I have ~100 files of data weighting about 500MB total, I need to access each of them about dozen times during a day. So I'm wondering, is it worth loading them all (0.5GB) into RAM in the morning, so they can be quickly accessible for the rest of the day. If FileOpen loads whole file into RAM each time, then it is. So that is my question: does FileOpen load whole file into RAM?
I looked thru similar posts on this forum, but didn't find clear answer. If someone could answer it, I would greatly appreciate it!
Thanks!
Does FileOpen load whole file into RAM? Topic is solved
Re: Does FileOpen load whole file into RAM?
Although I do not have a specific answer to your question, a practical approach to your question about speed is to time the two different versions of your scripts, to see which is faster. If you have a SSD, the outcome might depend less on opening the file and more on what you are doing with the file after that.
Re: Does FileOpen load whole file into RAM? Topic is solved
FileOpen() itself does not read the file contents. It opens a file for reading and/or writing. There isn’t even a variable identified with a FileOpen() call to read the file contents into. The return value is a file object, which provides the interface for subsequent operations, such as .Read() or .Write().
FileRead reads a file’s contents into memory (into a variable). If you want to work with the contents repeatedly directly in RAM, that might be the approach you want to take. The following are essentially equivalent:
FileRead reads a file’s contents into memory (into a variable). If you want to work with the contents repeatedly directly in RAM, that might be the approach you want to take. The following are essentially equivalent:
Code: Select all
FileRead, FileText, MyFile.txt
Code: Select all
MyFile := FileOpen("MyFile.txt", "r")
FileText := MyFile.Read()
MyFile.Close()
Re: Does FileOpen load whole file into RAM?
@mikeyww , @boiler Thank you for answers!
@boiler, so, does File.Read read only needed part of the file from disk, not the whole file?
@mikeyww, my concern is more about the toll it takes on disk (reading large amount of data from disk many times over), and less about speed of the process.
@boiler, so, does File.Read read only needed part of the file from disk, not the whole file?
@mikeyww, my concern is more about the toll it takes on disk (reading large amount of data from disk many times over), and less about speed of the process.
Re: Does FileOpen load whole file into RAM?
It can read part of the file from the disk. You can tell it how much of the file to read, the unit of length depending on the method used. The file pointer would need to be at or moved to the desired location. See File.Read() as well as the other read-related methods on that page for more details.
Re: Does FileOpen load whole file into RAM?
Yes, that's what my script does, it reads only specific part of large file, finding needed location by "table of contents" stored in other file.
I just was not sure whether File.Open/Read reads the whole file into RAM and then lets user to read any part of it, OR it just gets handle and then reads only requested part of it while the rest of file remains unloaded into RAM. As I understand now, not-requested part of file remains unloaded into RAM, correct?
Thank you for taking time to answer, your help is very appreciated!
Re: Does FileOpen load whole file into RAM?
Yes, it only reads the part you tell it to read. If you use File.Read(100), it will only read 100 characters into memory, not the rest of the file.
Re: Does FileOpen load whole file into RAM?
@boiler , thanks again!
Who is online
Users browsing this forum: Google [Bot] and 118 guests