16 #ifndef STXXL_MNG_DISK_ALLOCATOR_HEADER
17 #define STXXL_MNG_DISK_ALLOCATOR_HEADER
43 typedef std::pair<stxxl::int64, stxxl::int64>
place;
45 struct first_fit :
public std::binary_function<place, stxxl::int64, bool>
51 return (entry.second >= size);
55 typedef std::map<stxxl::int64, stxxl::int64>
sortseq;
67 void deallocation_error(
69 const sortseq::iterator& pred,
const sortseq::iterator& succ)
const;
80 storage->set_size(disk_bytes + extend_bytes);
81 add_free_region(disk_bytes, extend_bytes);
82 disk_bytes += extend_bytes;
91 autogrow(cfg.autogrow)
99 if (disk_bytes > cfg_bytes) {
100 storage->set_size(cfg_bytes);
111 return disk_bytes - free_bytes;
119 template <
unsigned BlockSize>
122 new_blocks(bids.
begin(), bids.
end());
125 template <
unsigned BlockSize>
129 template <
unsigned BlockSize>
132 for (
unsigned i = 0; i < bids.
size(); ++i)
133 delete_block(bids[i]);
137 template <
unsigned BlockSize>
143 ">(pos=" << bid.
offset <<
", size=" << bid.
size <<
144 "), free:" << free_bytes <<
" total:" << disk_bytes);
150 template <
unsigned BlockSize>
158 requested_size += cur->size;
163 STXXL_VERBOSE2(
"disk_allocator::new_blocks<BlockSize>, BlockSize = " << BlockSize <<
164 ", free:" << free_bytes <<
" total:" << disk_bytes <<
165 ", blocks: " << (end - begin) <<
166 " begin: " << static_cast<void*>(begin) <<
167 " end: " << static_cast<void*>(end) <<
168 ", requested_size=" << requested_size);
170 if (free_bytes < requested_size)
173 STXXL_ERRMSG(
"External memory block allocation error: " << requested_size <<
174 " bytes requested, " << free_bytes <<
175 " bytes free. Trying to extend the external memory space...");
178 grow_file(requested_size);
183 sortseq::iterator space;
184 space = std::find_if(free_space.begin(), free_space.end(),
187 if (space == free_space.end() && requested_size == BlockSize)
189 assert(end - begin == 1);
192 STXXL_ERRMSG(
"Warning: Severe external memory space fragmentation!");
195 STXXL_ERRMSG(
"External memory block allocation error: " << requested_size <<
196 " bytes requested, " << free_bytes <<
197 " bytes free. Trying to extend the external memory space...");
200 grow_file(BlockSize);
202 space = std::find_if(free_space.begin(), free_space.end(),
206 if (space != free_space.end())
210 free_space.erase(space);
211 if (region_size > requested_size)
212 free_space[region_pos + requested_size] = region_size - requested_size;
214 for (
stxxl::int64 pos = region_pos; begin != end; ++begin)
219 free_bytes -= requested_size;
226 STXXL_VERBOSE1(
"Warning, when allocating an external memory space, no contiguous region found");
229 assert(requested_size > BlockSize);
230 assert(end - begin > 1);
235 new_blocks(begin, middle);
236 new_blocks(middle, end);
243 #endif // !STXXL_MNG_DISK_ALLOCATOR_HEADER
void new_blocks(BIDArray< BlockSize > &bids)
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
disk_allocator(stxxl::file *storage, const disk_config &cfg)
void delete_block(const BID< BlockSize > &bid)
#define _STXXL_FORCE_SEQUENTIAL
stxxl::int64 offset
offset within the file of the block
uint64 size
file size to initially allocate
#define STXXL_END_NAMESPACE