Stxxl  1.4.0
containers/test_vector_export.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *  containers/test_vector_export.cpp
00003  *
00004  *  Part of the STXXL. See http://stxxl.sourceforge.net
00005  *
00006  *  Copyright (C) 2008 Johannes Singler <singler@ira.uka.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 //! \example containers/test_vector_export.cpp
00014 //! This is an example of use of \c stxxl::vector::export_files
00015 
00016 #include <iostream>
00017 #include <algorithm>
00018 #include <stxxl/vector>
00019 #include <stxxl/scan>
00020 
00021 typedef stxxl::int64 int64;
00022 
00023 
00024 int main()
00025 {
00026     try
00027     {
00028         // use non-randomized striping to avoid side effects on random generator
00029         typedef stxxl::VECTOR_GENERATOR<int64, 2, 2, (2 * 1024 * 1024), stxxl::striping>::result vector_type;
00030         vector_type v(int64(64 * 1024 * 1024) / sizeof(int64));
00031 
00032         stxxl::random_number32 rnd;
00033         int offset = rnd();
00034 
00035         STXXL_MSG("write " << v.size() << " elements");
00036 
00037         stxxl::ran32State = 0xdeadbeef;
00038         vector_type::size_type i;
00039 
00040         // fill the vector with increasing sequence of integer numbers
00041         for (i = 0; i < v.size(); ++i)
00042         {
00043             v[i] = i + offset;
00044             assert(v[i] == int64(i + offset));
00045         }
00046 
00047         v.flush();
00048 
00049         STXXL_MSG("export files");
00050         v.export_files("exported_");
00051     }
00052     catch (const std::exception & ex)
00053     {
00054         STXXL_MSG("Caught exception: " << ex.what());
00055     }
00056     catch (...)
00057     {
00058         STXXL_MSG("Caught unknown exception.");
00059     }
00060 
00061     return 0;
00062 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines