ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
#include <itkObjectStore.h>
A specialized memory management object for allocating and destroying contiguous blocks of objects.
ObjectStore implements a dynamically sizeable free memory store, from which instantiated objects can be borrowed and returned without always invoking calls to new/delete. This type of memory management is useful in situations where calls to new/delete may be expensive, such as a multithreaded environment to avoid the heap contention problem.
ObjectStore is designed to grow dynamically. Shrinking is a more difficult problem and is only done if it will not invalidate any pointers that have been "lent" to a calling application.
This implementation uses a very simple, list-based scheme to manage pointers that have been borrowed and returned. Memory overhead incurred is one pointer per object allocated. Because of this overhead, ObjectStore is not efficient for use with small objects such as native types.
Important notes on thread-safety: This object is thread-safe in the same sense that STL defines thread-safety: simultaneous operations on distinct containers are safe. It is the user's responsibility to apply appropriate mutex locks if the same container is used across multiple threads. One (or more) ObjectStore's can be safely be created for each thread -- and may even be more efficient in terms of memory use than sharing a single ObjectStore across threads. Calls to new and delete have been placed in critical sections in case a compiler's implementation of new/delete is not thread-safe.
Definition at line 63 of file itkObjectStore.h.
typedef SmartPointer< const Self > itk::ObjectStore< TObjectType >::ConstPointer |
Reimplemented from itk::Object.
Definition at line 70 of file itkObjectStore.h.
typedef std::vector< ObjectType * > itk::ObjectStore< TObjectType >::FreeListType |
Type of list for storing pointers to free memory.
Definition at line 82 of file itkObjectStore.h.
typedef TObjectType itk::ObjectStore< TObjectType >::ObjectType |
Type of the objects in storage.
Definition at line 76 of file itkObjectStore.h.
typedef SmartPointer< Self > itk::ObjectStore< TObjectType >::Pointer |
Reimplemented from itk::Object.
Definition at line 69 of file itkObjectStore.h.
typedef ObjectStore itk::ObjectStore< TObjectType >::Self |
typedef Object itk::ObjectStore< TObjectType >::Superclass |
Reimplemented from itk::Object.
Definition at line 68 of file itkObjectStore.h.
enum itk::ObjectStore::GrowthStrategyType |
Type of memory allocation strategy
Definition at line 85 of file itkObjectStore.h.
itk::ObjectStore< TObjectType >::ObjectStore | ( | ) | [protected] |
Set growth strategy to linear
itk::ObjectStore< TObjectType >::~ObjectStore | ( | ) | [protected] |
Set growth strategy to linear
itk::ObjectStore< TObjectType >::ObjectStore | ( | const Self & | ) | [private] |
ObjectType* itk::ObjectStore< TObjectType >::Borrow | ( | ) |
Borrow a pointer to an object from the memory store.
void itk::ObjectStore< TObjectType >::Clear | ( | ) |
Frees all memory in the container
virtual::itk::LightObject::Pointer itk::ObjectStore< TObjectType >::CreateAnother | ( | void | ) | const [virtual] |
Create an object from an instance, potentially deferring to a factory. This method allows you to create an instance of an object that is exactly the same type as the referring object. This is useful in cases where an object has been cast back to a base class.
Reimplemented from itk::Object.
SizeValueType itk::ObjectStore< TObjectType >::GetGrowthSize | ( | ) | [protected] |
Returns a new size to grow.
virtual GrowthStrategyType itk::ObjectStore< TObjectType >::GetGrowthStrategy | ( | ) | const [virtual] |
Set/Get the growth strategy.
virtual SizeValueType itk::ObjectStore< TObjectType >::GetLinearGrowthSize | ( | ) | const [virtual] |
Set/Get the linear growth size
virtual const char* itk::ObjectStore< TObjectType >::GetNameOfClass | ( | ) | const [virtual] |
Run-time type information (and related methods).
Reimplemented from itk::Object.
virtual SizeValueType itk::ObjectStore< TObjectType >::GetSize | ( | ) | const [virtual] |
Returns the size of the container. This is not the number of objects available, but the total number of objects allocated.
static Pointer itk::ObjectStore< TObjectType >::New | ( | ) | [static] |
Method for creation through the object factory.
Reimplemented from itk::Object.
void itk::ObjectStore< TObjectType >::operator= | ( | const Self & | ) | [private] |
Mutex lock to protect modification to the reference count
Reimplemented from itk::Object.
virtual void itk::ObjectStore< TObjectType >::PrintSelf | ( | std::ostream & | os, |
Indent | indent | ||
) | const [protected, virtual] |
Set growth strategy to linear
Reimplemented from itk::Object.
void itk::ObjectStore< TObjectType >::Reserve | ( | SizeValueType | n | ) |
Ensures that there are at least n elements allocated in the storage container. Will not shrink the container, but may enlarge the container.
void itk::ObjectStore< TObjectType >::Return | ( | ObjectType * | p | ) |
Return a pointer to the memory store for reuse. WARNING: The ObjectStore assumes a pointer is returned exactly once after each time it has been borrowed.
virtual void itk::ObjectStore< TObjectType >::SetGrowthStrategy | ( | GrowthStrategyType | _arg | ) | [virtual] |
Set/Get the growth strategy.
void itk::ObjectStore< TObjectType >::SetGrowthStrategyToExponential | ( | ) | [inline] |
Set growth strategy to exponential
Definition at line 122 of file itkObjectStore.h.
void itk::ObjectStore< TObjectType >::SetGrowthStrategyToLinear | ( | ) | [inline] |
Set growth strategy to linear
Definition at line 126 of file itkObjectStore.h.
virtual void itk::ObjectStore< TObjectType >::SetLinearGrowthSize | ( | SizeValueType | _arg | ) | [virtual] |
Set/Get the linear growth size
void itk::ObjectStore< TObjectType >::Squeeze | ( | ) |
Attempts to free memory that is not in use and shrink the size of the container. Not guaranteed to do anything.
FreeListType itk::ObjectStore< TObjectType >::m_FreeList [private] |
Pointers to objects available for borrowing.
Definition at line 161 of file itkObjectStore.h.
GrowthStrategyType itk::ObjectStore< TObjectType >::m_GrowthStrategy [private] |
Definition at line 155 of file itkObjectStore.h.
SizeValueType itk::ObjectStore< TObjectType >::m_LinearGrowthSize [private] |
Definition at line 158 of file itkObjectStore.h.
SizeValueType itk::ObjectStore< TObjectType >::m_Size [private] |
Definition at line 157 of file itkObjectStore.h.
std::vector< MemoryBlock > itk::ObjectStore< TObjectType >::m_Store [private] |
A list of MemoryBlocks that have been allocated.
Definition at line 164 of file itkObjectStore.h.