本文整理汇总了C++中cache_type::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ cache_type::insert方法的具体用法?C++ cache_type::insert怎么用?C++ cache_type::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cache_type
的用法示例。
在下文中一共展示了cache_type::insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cusparse_handle
inline cusparseHandle_t cusparse_handle(const command_queue &q) {
typedef std::shared_ptr<std::remove_pointer<cusparseHandle_t>::type> smart_handle;
typedef vex::detail::object_cache<vex::detail::index_by_context, smart_handle> cache_type;
static cache_type cache;
auto h = cache.find(q);
if (h == cache.end()) {
select_context(q);
cusparseHandle_t handle;
cuda_check( cusparseCreate(&handle) );
cuda_check( cusparseSetStream(handle, q.raw()) );
h = cache.insert(q, smart_handle(handle, detail::deleter()));
}
return h->second.get();
}
示例2: update_cache
/// Updates the cache with this new value
void update_cache(const KeyType &key, const ValueType &val) const{
cachelock.lock();
typename cache_type::iterator i = cache.find(key);
// create a new entry
if (i == cache.end()) {
cachelock.unlock();
// if we are out of room, remove the lru entry
if (cache.size() >= maxcache) remove_lru();
cachelock.lock();
// insert the element, remember the iterator so we can push it
// straight to the LRU list
std::pair<typename cache_type::iterator, bool> ret = cache.insert(std::make_pair(key, new lru_entry_type(key, val)));
if (ret.second) lruage.push_front(*(ret.first->second));
}
else {
// modify entry in place
i->second->value = val;
// swap to front of list
//boost::swap_nodes(lru_list_type::s_iterator_to(i->second), lruage.begin());
lruage.erase(lru_list_type::s_iterator_to(*(i->second)));
lruage.push_front(*(i->second));
}
cachelock.unlock();
}