You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Almost always cache check/put operations are followed by returning results to the callee, e.g.
auto val = std::shared_ptr{nullptr};
constauto [cached_val, cached_ok] = cache.TryGet(key);
if (!cached_ok) {
# for example, val is already a shared_ptr
val = Calc(key);
cache.Put(key, val);
return val;
}
return cached_val;
so current implentation doesn't allow storing shared_ptr, only shared_ptr<shared_ptr>.
Otherwise we must always copy the object to the cache because Put doesn't return a shared_ptr for newly created smart pointer, if it did, we could have done
constauto [cached_val, cached_ok] = cache.TryGet(key);
auto val = SomeType{};
if (!cached_ok) {
val = Calc(key);
auto val_shared_ptr = cache.Put(key, std::move(val));
return val_shared_ptr;
}
return cached_val;
The text was updated successfully, but these errors were encountered:
although, looking again at the code, even with a move in the latter case, Insert will anyways initiate a copy constructor, which does not seem right for large objects
Almost always cache check/put operations are followed by returning results to the callee, e.g.
so current implentation doesn't allow storing shared_ptr, only shared_ptr<shared_ptr>.
Otherwise we must always copy the object to the cache because Put doesn't return a shared_ptr for newly created smart pointer, if it did, we could have done
The text was updated successfully, but these errors were encountered: