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
73 #if STXXL_MNG_COUNT_ALLOCATION
82 #endif // STXXL_MNG_COUNT_ALLOCATION
85 template <
class BIDType,
class DiskAssignFunctor,
class BIDIteratorClass>
88 const DiskAssignFunctor& functor,
90 BIDIteratorClass out);
94 uint64 get_total_bytes()
const;
97 uint64 get_free_bytes()
const;
110 template <
class DiskAssignFunctor,
class BIDIteratorClass>
112 const DiskAssignFunctor& functor,
113 BIDIteratorClass bidbegin,
114 BIDIteratorClass bidend,
117 typedef typename std::iterator_traits<BIDIteratorClass>::value_type bid_type;
118 new_blocks_int<bid_type>(std::distance(bidbegin, bidend), functor, offset, bidbegin);
132 template <
class BlockType,
class DiskAssignFunctor,
class BIDIteratorClass>
135 const DiskAssignFunctor& functor,
136 BIDIteratorClass out,
139 typedef typename BlockType::bid_type bid_type;
140 new_blocks_int<bid_type>(nblocks, functor, offset, out);
151 template <
typename DiskAssignFunctor,
unsigned BLK_SIZE>
154 new_blocks_int<BID<BLK_SIZE> >(1, functor, offset, &bid);
162 template <
class BIDIteratorClass>
163 void delete_blocks(
const BIDIteratorClass& bidbegin,
const BIDIteratorClass& bidend);
167 template <
unsigned BLK_SIZE>
172 #if STXXL_MNG_COUNT_ALLOCATION
175 {
return m_total_allocation; }
179 {
return m_current_allocation; }
183 {
return m_maximum_allocation; }
184 #endif // STXXL_MNG_COUNT_ALLOCATION
188 template <
class BIDType,
class DiskAssignFunctor,
class OutputIterator>
189 void block_manager::new_blocks_int(
191 const DiskAssignFunctor& functor,
195 typedef BIDType bid_type;
207 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
239 template <
unsigned BLK_SIZE>
247 assert(bid.
storage->get_allocator_id() >= 0);
248 disk_allocators[bid.
storage->get_allocator_id()]->delete_block(bid);
251 #if STXXL_MNG_COUNT_ALLOCATION
252 m_current_allocation -= BLK_SIZE;
253 #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 Tp & STXXL_MAX(const Tp &a, const Tp &b)
file * storage
pointer to the file of the block
#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
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