00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00015
00016 #include <iostream>
00017 #include <stxxl/mng>
00018 #include <stxxl/bits/mng/buf_ostream.h>
00019 #include <stxxl/bits/mng/buf_istream.h>
00020
00021
00022 #define BLOCK_SIZE (1024 * 512)
00023
00024 typedef stxxl::typed_block<BLOCK_SIZE, unsigned> block_type;
00025 typedef stxxl::buf_ostream<block_type, stxxl::BIDArray<BLOCK_SIZE>::iterator> buf_ostream_type;
00026 typedef stxxl::buf_istream<block_type, stxxl::BIDArray<BLOCK_SIZE>::iterator> buf_istream_type;
00027
00028 int main()
00029 {
00030 const unsigned nblocks = 64;
00031 const unsigned nelements = nblocks * block_type::size;
00032 stxxl::BIDArray<BLOCK_SIZE> bids(nblocks);
00033
00034 stxxl::block_manager * bm = stxxl::block_manager::get_instance();
00035 bm->new_blocks(stxxl::striping(), bids.begin(), bids.end());
00036 {
00037 buf_ostream_type out(bids.begin(), 2);
00038 for (unsigned i = 0; i < nelements; i++)
00039 out << i;
00040 }
00041 {
00042 buf_istream_type in(bids.begin(), bids.end(), 2);
00043 for (unsigned i = 0; i < nelements; i++)
00044 {
00045 unsigned value;
00046 in >> value;
00047 if (value != i)
00048 {
00049 STXXL_ERRMSG("Error at position " << std::hex << i << " (" << value << ") block " << (i / block_type::size));
00050 }
00051 }
00052 }
00053 bm->delete_blocks(bids.begin(), bids.end());
00054 }