Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fastest technique to read a file into memory?

Is there a generally-accepted fastest technique which is used to read a file into memory in c++?

I will only be reading the file.

I have seen boost have an implementation and I have seen a couple other implementations on here but I would like to know what is considered the fastest?

Thank you in advance

In case it matters, I am considering files up to 1GB and this is for windows.

like image 893
mezamorphic Avatar asked May 31 '12 15:05

mezamorphic


2 Answers

Use memory-mapped files, maybe using the boost wrapper for portability.

If you want to read files bigger than the free, contiguous portion of your virtual address space, you can move the mapped portion of the file at will.

like image 61
Matteo Italia Avatar answered Oct 08 '22 16:10

Matteo Italia


Consider using Memory-Mapped Files for your case, as the files can be upto 1 GB size.

  • Memory-mapped files and how they work

And here you can start with win32 API:

  • MapViewOfFile

There are several other helpful API on MSDN page.

like image 41
Nawaz Avatar answered Oct 08 '22 17:10

Nawaz