Cortex
10.0.0-a4
|
#include <ObjectPool.h>
Public Types | |
enum | StoreMode { StoreCopy = 0, StoreReference } |
Enum used to specify how to store the pointer passed to the store() function. | |
![]() | |
typedef size_t | RefCount |
Public Member Functions | |
IE_CORE_DECLAREMEMBERPTR (ObjectPool) | |
ObjectPool (size_t maxMemory) | |
void | clear () |
bool | erase (const MurmurHash &hash) |
void | setMaxMemoryUsage (size_t maxMemory) |
Set the maximum memory cost of the items held in the pool, discarding any items if necessary. | |
size_t | getMaxMemoryUsage () const |
Get the maximum possible memory cost of all items held in the pool. | |
size_t | memoryUsage () const |
Returns the current memory cost of items held in the pool. | |
bool | contains (const MurmurHash &hash) const |
ConstObjectPtr | retrieve (const MurmurHash &hash) const |
Retrieves the Object with the given hash, or NULL if not held in the pool. | |
ConstObjectPtr | store (const Object *obj, StoreMode mode) |
![]() | |
IE_CORE_DECLAREMEMBERPTR (RefCounted) | |
void | addRef () const |
Add a reference to the current object. | |
void | removeRef () const |
Remove a reference from the current object. | |
RefCount | refCount () const |
Returns the current reference count. | |
Static Public Member Functions | |
static ObjectPool * | defaultObjectPool () |
The ObjectPool class implements a cache of Object instances indexed by their own hash and limited by the memory consumption. The function defaultObjectPool() returns a singleton object that should be used by most of the operations, so there will be one single place where the total memory used by IECore objects is defined.
bool IECore::ObjectPool::contains | ( | const MurmurHash & | hash | ) | const |
Returns true if the object with the given hash is in the pool. Note: this function doesn't garantee that retrieve() will return an object in a multi-threaded application.
|
static |
Returns a static ObjectPool instance to be used by anything wishing to share IECore::Object instances. It makes sense to use this wherever possible to conserve memory. This initially has a memory limit specified in megabytes by the IECORE_OBJECTPOOL_MEMORY environment variable. If it needs changing it's recommended to do that from a config file loaded by the ConfigLoader, to avoid multiple clients fighting over the same set of settings.
Stores a reference to the object or a copy to the object in the pool, depending on the storeMode parameter. If the object passed is already in the pool, than this function will have no effect and will return the stored object instead. If the storeMode is Reference, then the object should not be modified after the call to this function to prevent affecting the contents of the pool and it's memoryUsage count.