Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I want to pose a seemingly simple question that i can't find the answer nowhere. Is there a FAST modern algorithm for file input and/or output that can be compiled with all standard compliant C++ compilers and works for all operating systems without the requirement of external libraries ?

  1. i have found that the fastest way is to use memory mapped files, but that won't do cause we want the same piece of code working on all platforms
  2. we can't use apis like Win32 API cause that will make it platform specific
  3. i don't want to use c, i want the algorithm to be just pure c++ code with stl if feasible, not some ugly c with intermixed asm hack/trick
  4. frameworks or external libraries that don't belong in standart c++ shouldn't be used like wxWidgets, Qt, MFC etc.
  5. The big empasis of this whole question is that the algorithm is as FAST as possible, something along the lines of the speed of doing it with memory mapped files, even faster would be great but i know that is not possible

Have you ever seen something so crazy been researched by anyone else except me ? Is such an algorithm even possible ?

Thanks for any recommendations

like image 685
user258883 Avatar asked Jan 26 '10 00:01

user258883


2 Answers

With the following restrictions:

can be compiled with all standard compliant C++ compilers and works for all operating systems without the requirement of external libraries ?

You've pretty much restricted yourself to the standard library file IO functions. Maybe POSIX functions (depending on what subset of "all standard compliant C++ compilers" you're considering).

If they aren't fast enough for you, you'll have to start dropping some restrictions.

like image 54
Michael Burr Avatar answered Oct 17 '22 08:10

Michael Burr


This has nothing to do with an "algorithm".

When it comes to writing data to a file, you're at the mercy of the operating system - memory-mapped files are "fast" because you're just writing to memory, and the OS syncs it back out on its own time. If the OS doesn't support it, you're out of luck in that regard - unless you want to implement your own memory-mapping layer.

Incidentally, POSIX has mmap, so if you're limiting yourself to POSIX-compliant systems, you're fine.

like image 38
Anon. Avatar answered Oct 17 '22 09:10

Anon.