Blender V4.3
blender::memory_cache Namespace Reference

Namespaces

namespace  tests
 

Classes

struct  Cache
 
class  CachedValue
 
struct  StoredValue
 

Typedefs

using CacheMap = ConcurrentMap<std::reference_wrapper<const GenericKey>, StoredValue>
 

Functions

std::shared_ptr< CachedValueget_base (const GenericKey &key, FunctionRef< std::unique_ptr< CachedValue >()> compute_fn)
 
void set_approximate_size_limit (int64_t limit_in_bytes)
 
void clear ()
 
static Cacheget_cache ()
 
static void try_enforce_limit ()
 
static void set_new_logical_time (const StoredValue &stored_value, const int64_t new_time)
 
Inline Functions
template<typename T >
std::shared_ptr< const Tget (const GenericKey &key, FunctionRef< std::unique_ptr< T >()> compute_fn)
 

Typedef Documentation

◆ CacheMap

using blender::memory_cache::CacheMap = ConcurrentMap<std::reference_wrapper<const GenericKey>, StoredValue>

Definition at line 33 of file memory_cache.cc.

Function Documentation

◆ clear()

void blender::memory_cache::clear ( )

Remove all elements from the cache. Note that this does not guarantee that no elements are in the cache after the function returned. This is because another thread may have added a new element right after the clearing.

Definition at line 139 of file memory_cache.cc.

References BLI_assert, get_cache(), blender::memory_cache::Cache::global_mutex, blender::memory_cache::Cache::keys, lock, blender::memory_cache::Cache::map, blender::memory_cache::Cache::memory, blender::ConcurrentMap< Key, Value, Hash, IsEqual >::remove(), blender::memory_counter::MemoryCount::reset(), blender::memory_cache::Cache::size_in_bytes, and UNUSED_VARS_NDEBUG.

Referenced by blender::memory_cache::tests::TEST().

◆ get()

template<typename T >
std::shared_ptr< const T > blender::memory_cache::get ( const GenericKey & key,
FunctionRef< std::unique_ptr< T >()> compute_fn )
inline

Returns the value that corresponds to the given key. If it's not cached yet, #compute_fn is called and its result is cached for the next time.

If the cache is full, older values may be freed.

Definition at line 61 of file BLI_memory_cache.hh.

References get_base().

Referenced by blender::memory_cache::tests::TEST().

◆ get_base()

◆ get_cache()

static Cache & blender::memory_cache::get_cache ( )
static

Definition at line 56 of file memory_cache.cc.

Referenced by clear(), get_base(), set_approximate_size_limit(), and try_enforce_limit().

◆ set_approximate_size_limit()

void blender::memory_cache::set_approximate_size_limit ( int64_t limit_in_bytes)

Set how much memory the cache is allowed to use. This is only an approximation because counting the memory is not 100% accurate, and for some types the memory usage may even change over time.

Definition at line 132 of file memory_cache.cc.

References blender::memory_cache::Cache::approximate_limit, get_cache(), and try_enforce_limit().

Referenced by wm_init_userdef().

◆ set_new_logical_time()

static void blender::memory_cache::set_new_logical_time ( const StoredValue & stored_value,
const int64_t new_time )
static

Definition at line 64 of file memory_cache.cc.

References blender::memory_cache::StoredValue::last_use_time.

Referenced by get_base().

◆ try_enforce_limit()