Cortex  10.0.0-a4
Public Types | Public Member Functions | Static Public Member Functions | List of all members
IECore::ObjectPool Class Reference

#include <ObjectPool.h>

+ Inheritance diagram for IECore::ObjectPool:

Public Types

enum  StoreMode { StoreCopy = 0, StoreReference }
 Enum used to specify how to store the pointer passed to the store() function.
 
- Public Types inherited from IECore::RefCounted
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)
 
- Public Member Functions inherited from IECore::RefCounted
 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 ObjectPooldefaultObjectPool ()
 

Detailed Description

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.

Member Function Documentation

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 ObjectPool* IECore::ObjectPool::defaultObjectPool ( )
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.

ConstObjectPtr IECore::ObjectPool::store ( const Object obj,
StoreMode  mode 
)

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.


The documentation for this class was generated from the following file: