15 #ifndef STXXL_MNG_HEADER
16 #define STXXL_MNG_HEADER
28 #ifdef STXXL_BOOST_CONFIG
29 #include <boost/config.hpp>
36 #include <stxxl/bits/deprecated.h>
37 #include <stxxl/bits/io/request.h>
38 #include <stxxl/bits/io/file.h>
39 #include <stxxl/bits/io/create_file.h>
40 #include <stxxl/bits/noncopyable.h>
41 #include <stxxl/bits/singleton.h>
42 #include <stxxl/bits/mng/bid.h>
43 #include <stxxl/bits/mng/diskallocator.h>
44 #include <stxxl/bits/mng/block_alloc.h>
45 #include <stxxl/bits/mng/config.h>
48 __STXXL_BEGIN_NAMESPACE
61 friend class singleton<block_manager>;
63 DiskAllocator ** disk_allocators;
70 template <
class BIDType,
class DiskAssignFunctor,
class BIDIteratorClass>
72 const unsigned_type nblocks,
73 const DiskAssignFunctor & functor,
75 BIDIteratorClass out);
89 template <
class DiskAssignFunctor,
class BIDIteratorClass>
91 const DiskAssignFunctor & functor,
92 BIDIteratorClass bidbegin,
93 BIDIteratorClass bidend,
94 unsigned_type offset = 0)
96 typedef typename std::iterator_traits<BIDIteratorClass>::value_type bid_type;
97 new_blocks_int<bid_type>(std::distance(bidbegin, bidend), functor, offset, bidbegin);
111 template <
class BlockType,
class DiskAssignFunctor,
class BIDIteratorClass>
113 const unsigned_type nblocks,
114 const DiskAssignFunctor & functor,
115 BIDIteratorClass out,
116 unsigned_type offset = 0)
118 typedef typename BlockType::bid_type bid_type;
119 new_blocks_int<bid_type>(nblocks, functor, offset, out);
130 template <
typename DiskAssignFunctor,
unsigned BLK_SIZE>
133 new_blocks_int<BID<BLK_SIZE> >(1, functor, offset, &bid);
141 template <
class BIDIteratorClass>
142 void delete_blocks(
const BIDIteratorClass & bidbegin,
const BIDIteratorClass & bidend);
146 template <
unsigned BLK_SIZE>
153 template <
class BIDType,
class DiskAssignFunctor,
class OutputIterator>
154 void block_manager::new_blocks_int(
155 const unsigned_type nblocks,
156 const DiskAssignFunctor & functor,
157 unsigned_type offset,
160 typedef BIDType bid_type;
161 typedef BIDArray<bid_type::t_size> bid_array_type;
163 int_type * bl =
new int_type[ndisks];
164 bid_array_type * disk_bids =
new bid_array_type[ndisks];
165 file ** disk_ptrs =
new file *[nblocks];
167 memset(bl, 0, ndisks *
sizeof(int_type));
170 for (i = 0; i < nblocks; ++i)
172 const int disk = functor(offset + i);
173 disk_ptrs[i] = disk_files[disk];
177 for (i = 0; i < ndisks; ++i)
181 disk_bids[i].resize(bl[i]);
182 disk_allocators[i]->new_blocks(disk_bids[i]);
186 memset(bl, 0, ndisks *
sizeof(int_type));
188 OutputIterator it = out;
189 for (i = 0; i != nblocks; ++it, ++i)
192 bid_type bid(disk_ptrs[i], disk_bids[disk][bl[disk]++].offset);
194 STXXL_VERBOSE_BLOCK_LIFE_CYCLE(
"BLC:new " << FMT_BID(bid));
203 template <
unsigned BLK_SIZE>
208 if (!bid.is_managed())
210 STXXL_VERBOSE_BLOCK_LIFE_CYCLE(
"BLC:delete " << FMT_BID(bid));
217 template <
class BIDIteratorClass>
219 const BIDIteratorClass & bidbegin,
220 const BIDIteratorClass & bidend)
222 for (BIDIteratorClass it = bidbegin; it != bidend; it++)
229 #ifndef STXXL_DEFAULT_BLOCK_SIZE
230 #define STXXL_DEFAULT_BLOCK_SIZE(type) (2 * 1024 * 1024) // use traits
238 static file * create(
const std::string & io_impl,
239 const std::string & filename,
241 int queue_id = file::DEFAULT_QUEUE,
242 int allocator_id = file::NO_ALLOCATOR)
245 return create_file(io_impl, filename, options, queue_id, allocator_id);
251 __STXXL_END_NAMESPACE
253 #endif // !STXXL_MNG_HEADER
virtual void discard(offset_type offset, offset_type size)
Discard a region of the file (mark it unused) some specialized file types may need to know freed regi...
Definition: file.h:190
Defines interface of file.
Definition: file.h:90
Block size.
Definition: bid.h:44
file * storage
pointer to the file of the block
Definition: bid.h:48
virtual int get_allocator_id() const =0
Returns the file's allocator.
void delete_blocks(const BIDIteratorClass &bidbegin, const BIDIteratorClass &bidend)
Deallocates blocks.
Definition: mng.h:218
stxxl::int64 offset
offset within the file of the block
Definition: bid.h:49
void new_blocks(const DiskAssignFunctor &functor, BIDIteratorClass bidbegin, BIDIteratorClass bidend, unsigned_type offset=0)
Allocates new blocks.
Definition: mng.h:90
void new_block(const DiskAssignFunctor &functor, BID< BLK_SIZE > &bid, unsigned_type offset=0)
Definition: mng.h:131
void delete_block(const BID< BLK_SIZE > &bid)
Deallocates a block.
Definition: mng.h:204
void new_blocks(const unsigned_type nblocks, const DiskAssignFunctor &functor, BIDIteratorClass out, unsigned_type offset=0)
Definition: mng.h:112
Block manager class.
Definition: mng.h:59