Stxxl  1.4.0
mng/test_mng_recursive_alloc.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *  mng/test_mng_recursive_alloc.cpp
00003  *
00004  *  Part of the STXXL. See http://stxxl.sourceforge.net
00005  *
00006  *  Copyright (C) 2008 Andreas Beckmann <beckmann@cs.uni-frankfurt.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 #include <iostream>
00014 #include <stxxl/mng>
00015 
00016 #define BLOCK_SIZE (1024 * 1024 * 32)
00017 
00018 typedef stxxl::typed_block<BLOCK_SIZE, int> block_type;
00019 
00020 int main()
00021 {
00022     unsigned i;
00023     stxxl::int64 totalsize = 0;
00024     stxxl::config * config = stxxl::config::get_instance();
00025 
00026     for (i = 0; i < config->disks_number(); ++i)
00027         totalsize += config->disk_size(i);
00028     stxxl::unsigned_type totalblocks = totalsize / block_type::raw_size;
00029 
00030     STXXL_MSG("external memory: " << totalsize << " bytes  ==  " << totalblocks << " blocks");
00031 
00032     stxxl::BIDArray<BLOCK_SIZE> b5a(totalblocks / 5);
00033     stxxl::BIDArray<BLOCK_SIZE> b5b(totalblocks / 5);
00034     stxxl::BIDArray<BLOCK_SIZE> b5c(totalblocks / 5);
00035     stxxl::BIDArray<BLOCK_SIZE> b5d(totalblocks / 5);
00036     stxxl::BIDArray<BLOCK_SIZE> b2(totalblocks / 2);
00037 
00038     stxxl::block_manager * bm = stxxl::block_manager::get_instance();
00039 
00040     STXXL_MSG("get 4 x " << totalblocks / 5);
00041     bm->new_blocks(stxxl::striping(), b5a.begin(), b5a.end());
00042     bm->new_blocks(stxxl::striping(), b5b.begin(), b5b.end());
00043     bm->new_blocks(stxxl::striping(), b5c.begin(), b5c.end());
00044     bm->new_blocks(stxxl::striping(), b5d.begin(), b5d.end());
00045 
00046     STXXL_MSG("free 2 x " << totalblocks / 5);
00047     bm->delete_blocks(b5a.begin(), b5a.end());
00048     bm->delete_blocks(b5c.begin(), b5c.end());
00049 
00050     // the external memory should now be fragmented enough,
00051     // s.t. the following request needs to be split into smaller ones
00052     STXXL_MSG("get 1 x " << totalblocks / 2);
00053     bm->new_blocks(stxxl::striping(), b2.begin(), b2.end());
00054 
00055     bm->delete_blocks(b5b.begin(), b5b.end());
00056     bm->delete_blocks(b5d.begin(), b5d.end());
00057 
00058     bm->delete_blocks(b2.begin(), b2.end());
00059 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines