[go: up one dir, main page]

Menu

[5a71d8]: / mng / test.cpp  Maximize  Restore  History

Download this file

72 lines (55 with data), 1.7 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/***************************************************************************
* test.cpp
*
* Sat Aug 24 23:52:33 2002
* Copyright 2002 Roman Dementiev
* dementiev@mpi-sb.mpg.de
****************************************************************************/
#include <iostream>
#include "mng.h"
//! \example mng/test.cpp
//! This is an example of use of completion handlers, \c stxxl::block_manager, and
//! \c stxxl::typed_block
#define BLOCK_SIZE (1024*512)
struct MyType
{
int integer;
char chars[5];
};
using namespace stxxl;
struct my_handler
{
void operator () (request * req)
{
STXXL_MSG( req << " done, type="<<req->io_type() )
}
};
int
main ()
{
STXXL_MSG(sizeof(MyType)<<" "<<(BLOCK_SIZE % sizeof(MyType)));
STXXL_MSG(sizeof(typed_block < BLOCK_SIZE, MyType >)<<" "<<BLOCK_SIZE);
const unsigned nblocks = 64;
BIDArray < BLOCK_SIZE > bids (nblocks);
std::vector < int >disks (nblocks, 2);
stxxl::request_ptr * reqs = new stxxl::request_ptr[nblocks];
block_manager *bm = block_manager::get_instance ();
bm->new_blocks (striping (), bids.begin (), bids.end ());
typed_block < BLOCK_SIZE, MyType > * block = new typed_block < BLOCK_SIZE, MyType >;
unsigned i = 0;
for (i = 0; i < typed_block < BLOCK_SIZE, MyType >::size; i++)
{
block->elem[i].integer = 0xdeadbeef;
memcpy (block->elem[i].chars, "STXXL", 5);
}
for (i = 0; i < nblocks; i++)
reqs[i] = block->write (bids[i], my_handler());
std::cout << "Waiting " << std::endl;
stxxl::wait_all (reqs, nblocks);
bm->delete_blocks (bids.begin(), bids.end ());
delete [] reqs;
delete block;
// variable-size blocks
BIDArray<0> vbids (nblocks);
bm->new_blocks (striping (), vbids.begin (), vbids.end ());
}