ITK  4.9.0
Insight Segmentation and Registration Toolkit
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
itk::ObjectStore< TObjectType > Class Template Reference

#include <itkObjectStore.h>

+ Inheritance diagram for itk::ObjectStore< TObjectType >:
+ Collaboration diagram for itk::ObjectStore< TObjectType >:

Detailed Description

template<typename TObjectType>
class itk::ObjectStore< TObjectType >

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.

Warning
For efficiency reasons, the ObjectStore does not guard against the same pointer being Returned() more than once. Doing this could result in serious problems.

Definition at line 63 of file itkObjectStore.h.

Classes

struct  MemoryBlock
 

Public Types

typedef SmartPointer< const SelfConstPointer
 
typedef std::vector< ObjectType * > FreeListType
 
enum  GrowthStrategyType {
  LINEAR_GROWTH = 0,
  EXPONENTIAL_GROWTH = 1
}
 
typedef TObjectType ObjectType
 
typedef SmartPointer< SelfPointer
 
typedef ObjectStore Self
 
typedef Object Superclass
 
- Public Types inherited from itk::Object
typedef SmartPointer< const SelfConstPointer
 
typedef SmartPointer< SelfPointer
 
typedef Object Self
 
typedef LightObject Superclass
 
- Public Types inherited from itk::LightObject
typedef SmartPointer< const SelfConstPointer
 
typedef SmartPointer< SelfPointer
 
typedef LightObject Self
 

Public Member Functions

ObjectTypeBorrow ()
 
void Clear ()
 
virtual ::itk::LightObject::Pointer CreateAnother () const
 
virtual const char * GetNameOfClass () const
 
virtual SizeValueType GetSize () const
 
void Reserve (SizeValueType n)
 
void Return (ObjectType *p)
 
void SetGrowthStrategyToExponential ()
 
void SetGrowthStrategyToLinear ()
 
void Squeeze ()
 
virtual void SetLinearGrowthSize (SizeValueType _arg)
 
virtual SizeValueType GetLinearGrowthSize () const
 
virtual void SetGrowthStrategy (GrowthStrategyType _arg)
 
virtual GrowthStrategyType GetGrowthStrategy () const
 
- Public Member Functions inherited from itk::Object
unsigned long AddObserver (const EventObject &event, Command *)
 
unsigned long AddObserver (const EventObject &event, Command *) const
 
virtual void DebugOff () const
 
virtual void DebugOn () const
 
CommandGetCommand (unsigned long tag)
 
bool GetDebug () const
 
MetaDataDictionaryGetMetaDataDictionary ()
 
const MetaDataDictionaryGetMetaDataDictionary () const
 
virtual ModifiedTimeType GetMTime () const
 
virtual const TimeStampGetTimeStamp () const
 
bool HasObserver (const EventObject &event) const
 
void InvokeEvent (const EventObject &)
 
void InvokeEvent (const EventObject &) const
 
virtual void Modified () const
 
virtual void Register () const override
 
void RemoveAllObservers ()
 
void RemoveObserver (unsigned long tag)
 
void SetDebug (bool debugFlag) const
 
void SetMetaDataDictionary (const MetaDataDictionary &rhs)
 
virtual void SetReferenceCount (int) override
 
virtual void UnRegister () const noexceptoverride
 
virtual void SetObjectName (std::string _arg)
 
virtual const std::string & GetObjectName () const
 
- Public Member Functions inherited from itk::LightObject
virtual void Delete ()
 
virtual int GetReferenceCount () const
 
 itkCloneMacro (Self)
 
void Print (std::ostream &os, Indent indent=0) const
 

Static Public Member Functions

static Pointer New ()
 
- Static Public Member Functions inherited from itk::Object
static bool GetGlobalWarningDisplay ()
 
static void GlobalWarningDisplayOff ()
 
static void GlobalWarningDisplayOn ()
 
static Pointer New ()
 
static void SetGlobalWarningDisplay (bool flag)
 
- Static Public Member Functions inherited from itk::LightObject
static void BreakOnError ()
 
static Pointer New ()
 

Protected Member Functions

SizeValueType GetGrowthSize ()
 
 ObjectStore ()
 
virtual void PrintSelf (std::ostream &os, Indent indent) const override
 
 ~ObjectStore ()
 
- Protected Member Functions inherited from itk::Object
 Object ()
 
bool PrintObservers (std::ostream &os, Indent indent) const
 
virtual void SetTimeStamp (const TimeStamp &time)
 
virtual ~Object ()
 
- Protected Member Functions inherited from itk::LightObject
virtual LightObject::Pointer InternalClone () const
 
 LightObject ()
 
virtual void PrintHeader (std::ostream &os, Indent indent) const
 
virtual void PrintTrailer (std::ostream &os, Indent indent) const
 
virtual ~LightObject ()
 

Private Member Functions

 ObjectStore (const Self &) ITK_DELETE_FUNCTION
 
void operator= (const Self &) ITK_DELETE_FUNCTION
 

Private Attributes

FreeListType m_FreeList
 
GrowthStrategyType m_GrowthStrategy
 
SizeValueType m_LinearGrowthSize
 
SizeValueType m_Size
 
std::vector< MemoryBlockm_Store
 

Additional Inherited Members

- Protected Attributes inherited from itk::LightObject
AtomicInt< int > m_ReferenceCount
 

Member Typedef Documentation

template<typename TObjectType >
typedef SmartPointer< const Self > itk::ObjectStore< TObjectType >::ConstPointer

Definition at line 70 of file itkObjectStore.h.

template<typename TObjectType >
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.

template<typename TObjectType >
typedef TObjectType itk::ObjectStore< TObjectType >::ObjectType

Type of the objects in storage.

Definition at line 76 of file itkObjectStore.h.

template<typename TObjectType >
typedef SmartPointer< Self > itk::ObjectStore< TObjectType >::Pointer

Definition at line 69 of file itkObjectStore.h.

template<typename TObjectType >
typedef ObjectStore itk::ObjectStore< TObjectType >::Self

Standard typedefs.

Definition at line 67 of file itkObjectStore.h.

template<typename TObjectType >
typedef Object itk::ObjectStore< TObjectType >::Superclass

Definition at line 68 of file itkObjectStore.h.

Member Enumeration Documentation

template<typename TObjectType >
enum itk::ObjectStore::GrowthStrategyType

Type of memory allocation strategy

Enumerator
LINEAR_GROWTH 
EXPONENTIAL_GROWTH 

Definition at line 85 of file itkObjectStore.h.

Constructor & Destructor Documentation

template<typename TObjectType >
itk::ObjectStore< TObjectType >::ObjectStore ( )
protected
template<typename TObjectType >
itk::ObjectStore< TObjectType >::~ObjectStore ( )
protected
template<typename TObjectType >
itk::ObjectStore< TObjectType >::ObjectStore ( const Self )
private

Member Function Documentation

template<typename TObjectType >
ObjectType* itk::ObjectStore< TObjectType >::Borrow ( )

Borrow a pointer to an object from the memory store.

template<typename TObjectType >
void itk::ObjectStore< TObjectType >::Clear ( )

Frees all memory in the container

template<typename TObjectType >
virtual::itk::LightObject::Pointer itk::ObjectStore< TObjectType >::CreateAnother ( ) 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.

template<typename TObjectType >
SizeValueType itk::ObjectStore< TObjectType >::GetGrowthSize ( )
protected

Returns a new size to grow.

template<typename TObjectType >
virtual GrowthStrategyType itk::ObjectStore< TObjectType >::GetGrowthStrategy ( ) const
virtual

Set/Get the growth strategy.

template<typename TObjectType >
virtual SizeValueType itk::ObjectStore< TObjectType >::GetLinearGrowthSize ( ) const
virtual

Set/Get the linear growth size

template<typename TObjectType >
virtual const char* itk::ObjectStore< TObjectType >::GetNameOfClass ( ) const
virtual

Run-time type information (and related methods).

Reimplemented from itk::Object.

template<typename TObjectType >
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.

template<typename TObjectType >
static Pointer itk::ObjectStore< TObjectType >::New ( )
static
template<typename TObjectType >
void itk::ObjectStore< TObjectType >::operator= ( const Self )
private
template<typename TObjectType >
virtual void itk::ObjectStore< TObjectType >::PrintSelf ( std::ostream &  os,
Indent  indent 
) const
overrideprotectedvirtual

Methods invoked by Print() to print information about the object including superclasses. Typically not called by the user (use Print() instead) but used in the hierarchical print process to combine the output of several classes.

Reimplemented from itk::Object.

template<typename TObjectType >
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.

template<typename TObjectType >
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.

template<typename TObjectType >
virtual void itk::ObjectStore< TObjectType >::SetGrowthStrategy ( GrowthStrategyType  _arg)
virtual
template<typename TObjectType >
void itk::ObjectStore< TObjectType >::SetGrowthStrategyToExponential ( )
inline

Set growth strategy to exponential

Definition at line 122 of file itkObjectStore.h.

References itk::ObjectStore< TObjectType >::EXPONENTIAL_GROWTH, and itk::ObjectStore< TObjectType >::SetGrowthStrategy().

template<typename TObjectType >
void itk::ObjectStore< TObjectType >::SetGrowthStrategyToLinear ( )
inline

Set growth strategy to linear

Definition at line 126 of file itkObjectStore.h.

References itk::ObjectStore< TObjectType >::LINEAR_GROWTH, and itk::ObjectStore< TObjectType >::SetGrowthStrategy().

template<typename TObjectType >
virtual void itk::ObjectStore< TObjectType >::SetLinearGrowthSize ( SizeValueType  _arg)
virtual

Set/Get the linear growth size

template<typename TObjectType >
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.

Member Data Documentation

template<typename TObjectType >
FreeListType itk::ObjectStore< TObjectType >::m_FreeList
private

Pointers to objects available for borrowing.

Definition at line 164 of file itkObjectStore.h.

template<typename TObjectType >
GrowthStrategyType itk::ObjectStore< TObjectType >::m_GrowthStrategy
private

Definition at line 158 of file itkObjectStore.h.

template<typename TObjectType >
SizeValueType itk::ObjectStore< TObjectType >::m_LinearGrowthSize
private

Definition at line 161 of file itkObjectStore.h.

template<typename TObjectType >
SizeValueType itk::ObjectStore< TObjectType >::m_Size
private

Definition at line 160 of file itkObjectStore.h.

template<typename TObjectType >
std::vector< MemoryBlock > itk::ObjectStore< TObjectType >::m_Store
private

A list of MemoryBlocks that have been allocated.

Definition at line 167 of file itkObjectStore.h.


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