16 #ifndef STXXL_MNG_DISK_ALLOCATOR_HEADER
17 #define STXXL_MNG_DISK_ALLOCATOR_HEADER
45 typedef std::pair<stxxl::int64, stxxl::int64>
place;
47 struct first_fit :
public std::binary_function<place, stxxl::int64, bool>
53 return (entry.second >= size);
57 typedef std::map<stxxl::int64, stxxl::int64>
sortseq;
69 void deallocation_error(
71 const sortseq::iterator& pred,
const sortseq::iterator& succ)
const;
82 storage->set_size(disk_bytes + extend_bytes);
83 add_free_region(disk_bytes, extend_bytes);
84 disk_bytes += extend_bytes;
93 autogrow(cfg.autogrow)
101 if (disk_bytes > cfg_bytes) {
102 storage->set_size(cfg_bytes);
113 return disk_bytes - free_bytes;
121 template <
unsigned BlockSize>
124 new_blocks(bids.
begin(), bids.
end());
127 template <
unsigned BlockSize>
131 template <
unsigned BlockSize>
134 for (
unsigned i = 0; i < bids.
size(); ++i)
135 delete_block(bids[i]);
139 template <
unsigned BlockSize>
145 ">(pos=" << bid.
offset <<
", size=" << bid.
size <<
146 "), free:" << free_bytes <<
" total:" << disk_bytes);
152 template <
unsigned BlockSize>
160 requested_size += cur->size;
165 STXXL_VERBOSE2(
"disk_allocator::new_blocks<BlockSize>, BlockSize = " << BlockSize <<
166 ", free:" << free_bytes <<
" total:" << disk_bytes <<
167 ", blocks: " << (end - begin) <<
168 " begin: " << static_cast<void*>(begin) <<
169 " end: " << static_cast<void*>(end) <<
170 ", requested_size=" << requested_size);
172 if (free_bytes < requested_size)
176 "Out of external memory error: " << requested_size <<
177 " requested, " << free_bytes <<
" bytes free. "
178 "Maybe enable autogrow flags?");
181 STXXL_ERRMSG(
"External memory block allocation error: " << requested_size <<
182 " bytes requested, " << free_bytes <<
183 " bytes free. Trying to extend the external memory space...");
185 grow_file(requested_size);
190 sortseq::iterator space;
191 space = std::find_if(free_space.begin(), free_space.end(),
194 if (space == free_space.end() && requested_size == BlockSize)
196 assert(end - begin == 1);
199 STXXL_ERRMSG(
"Warning: Severe external memory space fragmentation!");
202 STXXL_ERRMSG(
"External memory block allocation error: " << requested_size <<
203 " bytes requested, " << free_bytes <<
204 " bytes free. Trying to extend the external memory space...");
207 grow_file(BlockSize);
209 space = std::find_if(free_space.begin(), free_space.end(),
213 if (space != free_space.end())
217 free_space.erase(space);
218 if (region_size > requested_size)
219 free_space[region_pos + requested_size] = region_size - requested_size;
221 for (
stxxl::int64 pos = region_pos; begin != end; ++begin)
226 free_bytes -= requested_size;
233 STXXL_VERBOSE1(
"Warning, when allocating an external memory space, no contiguous region found");
236 assert(requested_size > BlockSize);
237 assert(end - begin > 1);
242 new_blocks(begin, middle);
243 new_blocks(middle, end);
250 #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_THROW(exception_type, error_message)
Throws exception_type with "Error in [function] : [error_message]".
#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