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;
205 disk_ptrs[i] = disk_files[disk];
215 disk_bids[i].
resize(bl[i]);
216 disk_allocators[i]->new_blocks(disk_bids[i]);
222 OutputIterator it = out;
225 const int disk = disk_ptrs[i]->get_allocator_id();
226 bid_type bid(disk_ptrs[i], disk_bids[disk][bl[disk]++].offset);
231 #if STXXL_MNG_COUNT_ALLOCATION
232 m_total_allocation += nblocks * BIDType::size;
233 m_current_allocation += nblocks * BIDType::size;
234 m_maximum_allocation =
STXXL_MAX(m_maximum_allocation, m_current_allocation);
235 #endif // STXXL_MNG_COUNT_ALLOCATION
238 template <
unsigned BlockSize>
252 #if STXXL_MNG_COUNT_ALLOCATION
253 m_current_allocation -= BlockSize;
254 #endif // STXXL_MNG_COUNT_ALLOCATION
257 template <
class BIDIteratorClass>
258 void block_manager::delete_blocks(
259 const BIDIteratorClass& bidbegin,
260 const BIDIteratorClass& bidend)
262 for (BIDIteratorClass it = bidbegin; it != bidend; it++)
269 #ifndef STXXL_DEFAULT_BLOCK_SIZE
270 #define STXXL_DEFAULT_BLOCK_SIZE(type) (2 * 1024 * 1024) // use traits
277 #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.
virtual int get_allocator_id() const =0
Returns the file's disk allocator number.
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