[go: up one dir, main page]

Menu

[8bf46b]: / io / test_io.cpp  Maximize  Restore  History

Download this file

55 lines (41 with data), 1.3 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
/***************************************************************************
* test.cpp
*
* Sat Aug 24 23:52:27 2002
* Copyright 2002 Roman Dementiev
* dementiev@mpi-sb.mpg.de
****************************************************************************/
#include <stxxl>
//! \example io/test_io.cpp
//! This is an example of use of \c \<stxxl\> files, requests, and
//! completion tracking mechanisms, i.e. \c stxxl::file , \c stxxl::request , and
//! \c stxxl::mc
using namespace stxxl;
struct my_handler
{
void operator () (request * ptr)
{
STXXL_MSG("Request completed: "<< ptr)
}
};
int main()
{
std::cout << sizeof(void *) << std::endl;
const int size = 1024 * 384;
char *buffer = (char*)stxxl::aligned_alloc<4096>(size);
#ifdef BOOST_MSVC
const char * paths[2] = {"data1", "data2"};
#else
const char * paths[2] = {"/var/tmp/data1", "/var/tmp/data2"};
mmap_file file1(paths[0],file::CREAT | file::RDWR /* | file::DIRECT */,0);
file1.set_size(size*1024);
#endif
syscall_file file2(paths[1],file::CREAT | file::RDWR /* | file::DIRECT */,1);
request_ptr req[16];
unsigned i=0;
for(;i<16;i++)
req[i] = file2.awrite(buffer,i*size,size,my_handler());
wait_all(req,16);
stxxl::aligned_dealloc<4096>(buffer);
return 0;
}