Reputation: 35
When the file is opening in C++ and we start reading , does the whole file load to RAM from hard disk or just a block by a block ?
Upvotes: 1
Views: 295
Reputation: 2307
You decide how much to read into RAM. When you do 'getline' or read an amount into a buffer you are moving it from disk to RAM. If the file format is 'streamable' you can work on small chunks of the file at a time and still do the entire operation. Some file formats you need to read in most of the file to do an operation which can be a problem for multiple reasons.
If a file must be completely loaded before processing can begin you cannot start work immediately upon getting the first few bytes. This is a completely sequential operation which is slower than processing & loading at the same time.
As you mentioned RAM is smaller than disk, but even if a file can fit in RAM computers are often multi-tasking these days. Having 1 process need 4 GB of RAM when the same operation can be done with a few kilobytes can cause issues for other processes on the machine.
Upvotes: 3