Fast cross-platform algorithm for reading / writing a file in C ++

I want to imagine a simple question that I cannot find anywhere. Is there a FAST modern file input and / or output algorithm that can be compiled with all standard C ++ compilers and works for all operating systems without requiring external libraries?

  • I found that the fastest way is to use memory mapped files, but that will not lead to the fact that we want the same piece of code to work on all platforms.
  • we cannot use apis as a Win32 API because this will make it platform specific.
  • I don't want to use c, I want the algorithm to be just pure C ++ code with stl, if possible, and not some ugly c with intermixed asm hack / trick
  • frameworks or external libraries that do not belong to standard C ++ should not be used as wxWidgets, Qt, MFC, etc.
  • The big problem in this matter is that the algorithm is FAST as fast as possible , something like the speed of its execution with mapped memory files, it would be great even faster, but I know this is impossible

Have you ever seen that something so crazy was explored by someone other than me? Is such an algorithm possible?

Thanks for any recommendations.

+5
7

:

++ ?

IO . , POSIX ( , " ++ ", ).

, .

+9

"".

, - "", , . , - .

, POSIX mmap, , POSIX- , .

+9

" ", . , . ++.

++:

std::ifstream in_file;
std::ofstream out_file;

out_file << in_file.rdbuf();

, "copy file rdbuf". , . i/o ++, .

, DMA. ; ++ ( defacto, POSIX, ). , .

+4

:

  • .
  • (
  • , ). , - , POSIX + Win32.
  • , , mmap() Windows ( MapViewOfFile() .. - git mmap Windows, )
  • , C api ++, - . , ++ , .
  • , , " ", , . , .. Perfect - ;)
+2

, ( 2) , . , . - , . .

, , ( , ). .

, , , . .

+1

Fast IO :

  • /.

- . - IO, , - Perl IO. . Perl , IO .

+1

, (-).

, , "" - fread() .

I know that this is a fairly simple and general answer, but it is as specific as you can do without being more platform-oriented or know more about the specific input you are processing.

0
source

All Articles