16 #ifndef STXXL_MNG_DISK_ALLOCATOR_HEADER
17 #define STXXL_MNG_DISK_ALLOCATOR_HEADER
44 typedef std::pair<stxxl::int64, stxxl::int64>
place;
46 struct first_fit :
public std::binary_function<place, stxxl::int64, bool>
52 return (entry.second >= size);
56 typedef std::map<stxxl::int64, stxxl::int64>
sortseq;
68 void deallocation_error(
70 const sortseq::iterator& pred,
const sortseq::iterator& succ)
const;
81 storage->set_size(disk_bytes + extend_bytes);
82 add_free_region(disk_bytes, extend_bytes);
83 disk_bytes += extend_bytes;
92 autogrow(cfg.autogrow)
100 if (disk_bytes > cfg_bytes) {
101 storage->set_size(cfg_bytes);
112 return disk_bytes - free_bytes;
120 template <
unsigned BLK_SIZE>
123 new_blocks(bids.
begin(), bids.
end());
126 template <
unsigned BLK_SIZE>
130 template <
unsigned BLK_SIZE>
133 for (
unsigned i = 0; i < bids.
size(); ++i)
134 delete_block(bids[i]);
138 template <
unsigned BLK_SIZE>
144 ">(pos=" << bid.
offset <<
", size=" << bid.
size <<
145 "), free:" << free_bytes <<
" total:" << disk_bytes);
151 template <
unsigned BLK_SIZE>
159 requested_size += cur->size;
164 STXXL_VERBOSE2(
"disk_allocator::new_blocks<BLK_SIZE>, BLK_SIZE = " << BLK_SIZE <<
165 ", free:" << free_bytes <<
" total:" << disk_bytes <<
166 ", blocks: " << (end - begin) <<
167 " begin: " << static_cast<void*>(begin) <<
168 " end: " << static_cast<void*>(end) <<
169 ", requested_size=" << requested_size);
171 if (free_bytes < requested_size)
174 STXXL_ERRMSG(
"External memory block allocation error: " << requested_size <<
175 " bytes requested, " << free_bytes <<
176 " bytes free. Trying to extend the external memory space...");
179 grow_file(requested_size);
184 sortseq::iterator space;
185 space = std::find_if(free_space.begin(), free_space.end(),
188 if (space == free_space.end() && requested_size == BLK_SIZE)
190 assert(end - begin == 1);
193 STXXL_ERRMSG(
"Warning: Severe external memory space fragmentation!");
196 STXXL_ERRMSG(
"External memory block allocation error: " << requested_size <<
197 " bytes requested, " << free_bytes <<
198 " bytes free. Trying to extend the external memory space...");
203 space = std::find_if(free_space.begin(), free_space.end(),
207 if (space != free_space.end())
211 free_space.erase(space);
212 if (region_size > requested_size)
213 free_space[region_pos + requested_size] = region_size - requested_size;
215 for (
stxxl::int64 pos = region_pos; begin != end; ++begin)
220 free_bytes -= requested_size;
227 STXXL_VERBOSE1(
"Warning, when allocating an external memory space, no contiguous region found");
230 assert(requested_size > BLK_SIZE);
231 assert(end - begin > 1);
236 new_blocks(begin, middle);
237 new_blocks(middle, end);
244 #endif // !STXXL_MNG_DISK_ALLOCATOR_HEADER
void delete_block(const BID< BLK_SIZE > &bid)
void unlock()
unlock mutex hold prematurely
int64 get_used_bytes() const
#define STXXL_VERBOSE2(x)
size_type size() const
return number of items in vector
iterator end()
return mutable iterator beyond last element
std::map< stxxl::int64, stxxl::int64 > sortseq
std::pair< stxxl::int64, stxxl::int64 > place
void grow_file(stxxl::int64 extend_bytes)
Defines interface of file.
Encapsulate the configuration of one "disk". The disk is actually a file I/O object which block_manag...
iterator begin()
return mutable iterator to first element
Aquire a lock that's valid until the end of scope.
#define STXXL_BEGIN_NAMESPACE
int64 get_total_bytes() const
#define STXXL_VERBOSE1(x)
int64 get_free_bytes() const
void new_blocks(BIDArray< BLK_SIZE > &bids)
disk_allocator(stxxl::file *storage, const disk_config &cfg)
stxxl::int64 offset
offset within the file of the block
#define _STXXL_FORCE_SEQUENTIAL
uint64 size
file size to initially allocate
#define STXXL_END_NAMESPACE