Reputation: 113
I am receiving this assertion failed error when trying to insert an element in a stxxl map.
The entire assertion error is the following:
resCache: /usr/include/stxxl/bits/containers/btree/btree.h:470: std::pair >, bool> stxxl::btree::btree::insert(const value_type&) [with KeyType = e_my_key, DataType = unsigned int, CompareType = comp_type, unsigned int RawNodeSize = 16384u, unsigned int RawLeafSize = 131072u, PDAllocStrategy = stxxl::SR, stxxl::btree::btree::value_type = std::pair]: Assertion `it != root_node_.end()' failed. Aborted
Any idea?
Edit: Here's the code fragment
void request_handler::handle_request(my_key& query, reply& rep)
{
c_++;
std::cout << "Received query " << query.content << " by thread " << boost::this_thread::get_id() << ". It is number " << c_ << "\n";
strcpy(element.first.content, query.content);
element.second = c_;
testcache_.insert(element);
STXXL_MSG("Records in map: " << testcache_.size());
}
Edit2 here's more details (I omit constants, e.g. MAX_QUERY_LEN)
struct comp_type : std::binary_function<my_key, my_key, bool>
{
bool operator () (const my_key & a, const my_key & b) const
{
return strncmp(a.content, b.content, MAX_QUERY_LEN) < 0;
}
static my_key max_value()
{
return max_key;
}
static my_key min_value()
{
return min_key;
}
};
typedef stxxl::map<my_key, my_data, comp_type> cacheType;
cacheType testcache_;
request_handler::request_handler()
:testcache_(NODE_CACHE_SIZE, LEAF_CACHE_SIZE)
{
c_ = 0;
memset(max_key.content, (std::numeric_limits<unsigned char>::max)(), MAX_QUERY_LEN);
memset(min_key.content, (std::numeric_limits<unsigned char>::min)(), MAX_QUERY_LEN);
testcache_.enable_prefetching();
STXXL_MSG("Records in map: " << testcache_.size());
}
Upvotes: 0
Views: 154
Reputation: 249123
Here's an idea: use valgrind. It is often very helpful when diagnosing what may be a non-local bug in your program. That is, you may be corrupting your container somewhere along the way (a common mistake is erasing while iterating). So the assertion that is failing is likely due to you having done something wrong with the container, but maybe not immediately before the program died. Valgrind can help you find invalid memory accesses and so on.
Upvotes: 0