[go: up one dir, main page]

Menu

[dc7c28]: / mng / test_streams.cpp  Maximize  Restore  History

Download this file

55 lines (44 with data), 1.6 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/***************************************************************************
* test.cpp
*
* Sat Aug 24 23:52:33 2002
* Copyright 2002 Roman Dementiev
* dementiev@mpi-sb.mpg.de
****************************************************************************/
#include <iostream>
#include "stxxl/bits/mng/mng.h"
#include "stxxl/bits/mng/buf_ostream.h"
#include "stxxl/bits/mng/buf_istream.h"
//! \example mng/test_streams.cpp
//! This is an example of use of \c stxxl::buf_istream and \c stxxl::buf_ostream
#define BLOCK_SIZE (1024 * 512)
using namespace stxxl;
typedef typed_block<BLOCK_SIZE, int> block_type;
typedef buf_ostream<block_type, BIDArray<BLOCK_SIZE>::iterator> buf_ostream_type;
typedef buf_istream<block_type, BIDArray<BLOCK_SIZE>::iterator> buf_istream_type;
int main()
{
const unsigned nblocks = 64;
const unsigned nelements = nblocks * block_type::size;
BIDArray<BLOCK_SIZE> bids(nblocks);
block_manager * bm = block_manager::get_instance ();
bm->new_blocks (striping (), bids.begin (), bids.end ());
{
buf_ostream_type out(bids.begin(), 2);
for (unsigned i = 0; i < nelements; i++)
out << i;
}
{
buf_istream_type in(bids.begin(), bids.end(), 2);
for (unsigned i = 0; i < nelements; i++)
{
int value;
in >> value;
if (value != int (i))
{
STXXL_ERRMSG("Error at position " << std::hex << i << " (" << value << ") block " << (i / block_type::size) );
}
}
}
bm->delete_blocks (bids.begin (), bids.end ());
}