15 #ifndef STXXL_MNG_BLOCK_MANAGER_HEADER
16 #define STXXL_MNG_BLOCK_MANAGER_HEADER
50 #ifndef STXXL_MNG_COUNT_ALLOCATION
51 #define STXXL_MNG_COUNT_ALLOCATION 1
52 #endif // STXXL_MNG_COUNT_ALLOCATION
71 #if STXXL_MNG_COUNT_ALLOCATION
80 #endif // STXXL_MNG_COUNT_ALLOCATION
83 template <
class BIDType,
class DiskAssignFunctor,
class BIDIteratorClass>
86 const DiskAssignFunctor& functor,
88 BIDIteratorClass out);
92 uint64 get_total_bytes()
const;
95 uint64 get_free_bytes()
const;
108 template <
class DiskAssignFunctor,
class BIDIteratorClass>
110 const DiskAssignFunctor& functor,
111 BIDIteratorClass bidbegin,
112 BIDIteratorClass bidend,
115 typedef typename std::iterator_traits<BIDIteratorClass>::value_type bid_type;
116 new_blocks_int<bid_type>(std::distance(bidbegin, bidend), functor, offset, bidbegin);
130 template <
class BlockType,
class DiskAssignFunctor,
class BIDIteratorClass>
133 const DiskAssignFunctor& functor,
134 BIDIteratorClass out,
137 typedef typename BlockType::bid_type bid_type;
138 new_blocks_int<bid_type>(nblocks, functor, offset, out);
149 template <
typename DiskAssignFunctor,
unsigned BLK_SIZE>
152 new_blocks_int<BID<BLK_SIZE> >(1, functor, offset, &bid);
160 template <
class BIDIteratorClass>
161 void delete_blocks(
const BIDIteratorClass& bidbegin,
const BIDIteratorClass& bidend);
165 template <
unsigned BLK_SIZE>
170 #if STXXL_MNG_COUNT_ALLOCATION
173 {
return m_total_allocation; }
177 {
return m_current_allocation; }
181 {
return m_maximum_allocation; }
182 #endif // STXXL_MNG_COUNT_ALLOCATION
185 template <
class BIDType,
class DiskAssignFunctor,
class OutputIterator>
186 void block_manager::new_blocks_int(
188 const DiskAssignFunctor& functor,
192 typedef BIDType bid_type;
204 disk_ptrs[i] = disk_files[disk];
212 disk_bids[i].
resize(bl[i]);
213 disk_allocators[i]->new_blocks(disk_bids[i]);
219 OutputIterator it = out;
222 const int disk = disk_ptrs[i]->get_allocator_id();
223 bid_type bid(disk_ptrs[i], disk_bids[disk][bl[disk]++].offset);
228 #if STXXL_MNG_COUNT_ALLOCATION
229 m_total_allocation += nblocks * BIDType::size;
230 m_current_allocation += nblocks * BIDType::size;
231 m_maximum_allocation =
STXXL_MAX(m_maximum_allocation, m_current_allocation);
232 #endif // STXXL_MNG_COUNT_ALLOCATION
235 template <
unsigned BlockSize>
243 assert(bid.
storage->get_allocator_id() >= 0);
244 disk_allocators[bid.
storage->get_allocator_id()]->delete_block(bid);
247 #if STXXL_MNG_COUNT_ALLOCATION
248 m_current_allocation -= BlockSize;
249 #endif // STXXL_MNG_COUNT_ALLOCATION
252 template <
class BIDIteratorClass>
253 void block_manager::delete_blocks(
254 const BIDIteratorClass& bidbegin,
255 const BIDIteratorClass& bidend)
257 for (BIDIteratorClass it = bidbegin; it != bidend; it++)
264 #ifndef STXXL_DEFAULT_BLOCK_SIZE
265 #define STXXL_DEFAULT_BLOCK_SIZE(type) (2 * 1024 * 1024) // use traits
272 #endif // !STXXL_MNG_BLOCK_MANAGER_HEADER
uint64 get_maximum_allocation() const
return maximum number of bytes allocated during program run.
uint64 m_current_allocation
currently allocated bytes
unsigned long long int uint64
uint64 get_current_allocation() const
return currently allocated bytes
void new_blocks(const unsigned_type nblocks, const DiskAssignFunctor &functor, BIDIteratorClass out, unsigned_type offset=0)
Allocates new blocks according to the strategy given by functor and stores block identifiers to the o...
#define STXXL_VERBOSE_BLOCK_LIFE_CYCLE
uint64 m_total_allocation
total requested allocation in bytes
disk_allocator ** disk_allocators
Defines interface of file.
void memzero()
Zero the whole array content.
const Type & STXXL_MAX(const Type &a, const Type &b)
#define STXXL_BEGIN_NAMESPACE
void new_block(const DiskAssignFunctor &functor, BID< BLK_SIZE > &bid, unsigned_type offset=0)
Allocates a new block according to the strategy given by functor and stores the block identifier to b...
void new_blocks(const DiskAssignFunctor &functor, BIDIteratorClass bidbegin, BIDIteratorClass bidend, unsigned_type offset=0)
Allocates new blocks.
choose_int_types< my_pointer_size >::unsigned_type unsigned_type
file * storage
pointer to the file of the block
uint64 m_maximum_allocation
maximum number of bytes allocated during program run.
stxxl::int64 offset
offset within the file of the block
uint64 get_total_allocation() const
return total requested allocation in bytes
#define STXXL_END_NAMESPACE
void resize(size_type newsize)
resize the array to contain exactly newsize items