io/test_io.cpp

This is an example of use of <stxxl> files, requests, and completion tracking mechanisms, i.e. stxxl::file , stxxl::request

00001 /***************************************************************************
00002  *  io/test_io.cpp
00003  *
00004  *  Part of the STXXL. See http://stxxl.sourceforge.net
00005  *
00006  *  Copyright (C) 2002 Roman Dementiev <dementiev@mpi-sb.mpg.de>
00007  *
00008  *  Distributed under the Boost Software License, Version 1.0.
00009  *  (See accompanying file LICENSE_1_0.txt or copy at
00010  *  http://www.boost.org/LICENSE_1_0.txt)
00011  **************************************************************************/
00012 
00013 #include <stxxl/io>
00014 #include <stxxl/aligned_alloc>
00015 
00019 
00020 using stxxl::file;
00021 
00022 
00023 struct my_handler
00024 {
00025     void operator () (stxxl::request * ptr)
00026     {
00027         STXXL_MSG("Request completed: " << ptr);
00028     }
00029 };
00030 
00031 namespace stxxl
00032 {
00033     std::string hr(uint64, const char *);
00034 }
00035 
00036 int main()
00037 {
00038     std::cout << sizeof(void *) << std::endl;
00039     const int size = 1024 * 384;
00040     char * buffer = (char *)stxxl::aligned_alloc<4096>(size);
00041     memset(buffer, 0, size);
00042 #ifdef BOOST_MSVC
00043     const char * paths[2] = { "data1", "data2" };
00044 #else
00045     const char * paths[2] = { "/var/tmp/data1", "/var/tmp/data2" };
00046     stxxl::mmap_file file1(paths[0], file::CREAT | file::RDWR /* | file::DIRECT */, 0);
00047     file1.set_size(size * 1024);
00048 #endif
00049 
00050     stxxl::syscall_file file2(paths[1], file::CREAT | file::RDWR /* | file::DIRECT */, 1);
00051 
00052     stxxl::request_ptr req[16];
00053     unsigned i = 0;
00054     for ( ; i < 16; i++)
00055         req[i] = file2.awrite(buffer, i * size, size, my_handler());
00056 
00057 
00058     wait_all(req, 16);
00059 
00060     stxxl::aligned_dealloc<4096>(buffer);
00061 
00062     std::cout << *(stxxl::stats::get_instance());
00063 
00064     stxxl::uint64 sz = 123;
00065     for (i = 0; i < 20; ++i, sz *= 10)
00066         STXXL_MSG(stxxl::hr(sz, "B"));
00067     STXXL_MSG(stxxl::hr((std::numeric_limits<stxxl::uint64>::max)(), "B"));
00068 
00069     unlink(paths[0]);
00070     unlink(paths[1]);
00071 
00072     return 0;
00073 }

Generated on Thu Jun 4 10:21:44 2009 for Stxxl by  doxygen 1.4.7