Search code examples
c++stxxl

stxxl save and read vector from disk file


I'm struggling in trying to use the stxxl library in a way, that I cannot only store the data from their vector structure into a file but also recover it from that file in a rerun of my program.

I found out that you can construct a vector from a file ( http://stxxl.sourceforge.net/tags/master/classstxxl_1_1vector.html#a4d9029657cc11315cb77955fae70b877 ) but the class "file" only contains these functions ( http://stxxl.sourceforge.net/tags/master/classstxxl_1_1file.html ) with no way (that I can see) to actually access an existing file with some given path.

Does someone who worked with this library before have an idea how to do that?

Thanks in advance


Solution

  • stxxl::file is an interface base class. Depending on your operating system, you want one of the derived classes

    • stxxl::syscall_file for UNIX, Linux, and Mac OS X using POSIX read and write,
    • stxxl::wincall_file for Windows, or
    • stxxl::linuxaio_file for Linux using the SYS_io_* asynchronous I/O syscalls (see man 7 aio for details). This requires STXXL 1.4.1.

    You can use the stxxl::create_file function to decide at runtime which backend to use. Set the io_impl parameter to "syscall", "wincall", or "linuxaio", respectively.