ITK  5.2.0
Insight Toolkit
Classes | Public Types | Public Member Functions | Static Public Member Functions | 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 >:

Classes

struct  MemoryBlock
 

Public Types

using ConstPointer = SmartPointer< const Self >
 
using FreeListType = std::vector< ObjectType * >
 
using GrowthStrategyEnum = ObjectStoreEnums::GrowthStrategy
 
using ObjectType = TObjectType
 
using Pointer = SmartPointer< Self >
 
using Self = ObjectStore
 
using Superclass = Object
 
- Public Types inherited from itk::Object
using ConstPointer = SmartPointer< const Self >
 
using Pointer = SmartPointer< Self >
 
using Self = Object
 
using Superclass = LightObject
 
- Public Types inherited from itk::LightObject
using ConstPointer = SmartPointer< const Self >
 
using Pointer = SmartPointer< Self >
 
using Self = LightObject
 

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 Squeeze ()
 
- Public Member Functions inherited from itk::Object
unsigned long AddObserver (const EventObject &event, Command *)
 
unsigned long AddObserver (const EventObject &event, Command *) const
 
unsigned long AddObserver (const EventObject &event, std::function< void(const EventObject &)> function) 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
 
void Register () const override
 
void RemoveAllObservers ()
 
void RemoveObserver (unsigned long tag)
 
void SetDebug (bool debugFlag) const
 
void SetReferenceCount (int) override
 
void UnRegister () const noexcept override
 
void SetMetaDataDictionary (const MetaDataDictionary &rhs)
 
void SetMetaDataDictionary (MetaDataDictionary &&rrhs)
 
virtual void SetObjectName (std::string _arg)
 
virtual const std::string & GetObjectName () const
 
- Public Member Functions inherited from itk::LightObject
Pointer Clone () const
 
virtual void Delete ()
 
virtual int GetReferenceCount () const
 
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 val)
 
- Static Public Member Functions inherited from itk::LightObject
static void BreakOnError ()
 
static Pointer New ()
 
GrowthStrategyEnum m_GrowthStrategy
 
SizeValueType m_Size
 
SizeValueType m_LinearGrowthSize
 
FreeListType m_FreeList
 
std::vector< MemoryBlockm_Store
 
virtual void SetLinearGrowthSize (SizeValueType _arg)
 
virtual SizeValueType GetLinearGrowthSize () const
 
virtual void SetGrowthStrategy (const GrowthStrategyEnum _arg)
 
virtual GrowthStrategyEnum GetGrowthStrategy () const
 
void SetGrowthStrategyToExponential ()
 
void SetGrowthStrategyToLinear ()
 
 ObjectStore ()
 
 ~ObjectStore () override
 
void PrintSelf (std::ostream &os, Indent indent) const override
 
SizeValueType GetGrowthSize ()
 

Additional Inherited Members

- Protected Member Functions inherited from itk::Object
 Object ()
 
 ~Object () override
 
bool PrintObservers (std::ostream &os, Indent indent) const
 
virtual void SetTimeStamp (const TimeStamp &timeStamp)
 
- 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 ()
 
- Protected Attributes inherited from itk::LightObject
std::atomic< int > m_ReferenceCount
 

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 84 of file itkObjectStore.h.

Member Typedef Documentation

◆ ConstPointer

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

Definition at line 93 of file itkObjectStore.h.

◆ FreeListType

template<typename TObjectType >
using itk::ObjectStore< TObjectType >::FreeListType = std::vector<ObjectType *>

Type of list for storing pointers to free memory.

Definition at line 105 of file itkObjectStore.h.

◆ GrowthStrategyEnum

template<typename TObjectType >
using itk::ObjectStore< TObjectType >::GrowthStrategyEnum = ObjectStoreEnums::GrowthStrategy

Definition at line 107 of file itkObjectStore.h.

◆ ObjectType

template<typename TObjectType >
using itk::ObjectStore< TObjectType >::ObjectType = TObjectType

Type of the objects in storage.

Definition at line 102 of file itkObjectStore.h.

◆ Pointer

template<typename TObjectType >
using itk::ObjectStore< TObjectType >::Pointer = SmartPointer<Self>

Definition at line 92 of file itkObjectStore.h.

◆ Self

template<typename TObjectType >
using itk::ObjectStore< TObjectType >::Self = ObjectStore

Standard type alias.

Definition at line 90 of file itkObjectStore.h.

◆ Superclass

template<typename TObjectType >
using itk::ObjectStore< TObjectType >::Superclass = Object

Definition at line 91 of file itkObjectStore.h.

Constructor & Destructor Documentation

◆ ObjectStore()

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

Pointers to objects available for borrowing.

◆ ~ObjectStore()

template<typename TObjectType >
itk::ObjectStore< TObjectType >::~ObjectStore ( )
overrideprotected

Pointers to objects available for borrowing.

Member Function Documentation

◆ Borrow()

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

Borrow a pointer to an object from the memory store.

◆ Clear()

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

Frees all memory in the container

◆ CreateAnother()

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.

◆ GetGrowthSize()

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

Returns a new size to grow.

◆ GetGrowthStrategy()

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

Pointers to objects available for borrowing.

◆ GetLinearGrowthSize()

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

Pointers to objects available for borrowing.

◆ GetNameOfClass()

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

Run-time type information (and related methods).

Reimplemented from itk::Object.

◆ GetSize()

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.

◆ New()

template<typename TObjectType >
static Pointer itk::ObjectStore< TObjectType >::New ( )
static

Method for creation through the object factory.

◆ PrintSelf()

template<typename TObjectType >
void itk::ObjectStore< TObjectType >::PrintSelf ( std::ostream &  os,
Indent  indent 
) const
overrideprotectedvirtual

Pointers to objects available for borrowing.

Reimplemented from itk::Object.

◆ Reserve()

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.

◆ Return()

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.

◆ SetGrowthStrategy()

template<typename TObjectType >
virtual void itk::ObjectStore< TObjectType >::SetGrowthStrategy ( const GrowthStrategyEnum  _arg)
virtual

Set/Get the growth strategy.

◆ SetGrowthStrategyToExponential()

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

Set growth strategy to exponential

Definition at line 155 of file itkObjectStore.h.

◆ SetGrowthStrategyToLinear()

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

Set growth strategy to linear

Definition at line 162 of file itkObjectStore.h.

◆ SetLinearGrowthSize()

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

Set/Get the linear growth size

◆ Squeeze()

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

◆ m_FreeList

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

Pointers to objects available for borrowing.

Definition at line 208 of file itkObjectStore.h.

◆ m_GrowthStrategy

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

Pointers to objects available for borrowing.

Definition at line 202 of file itkObjectStore.h.

◆ m_LinearGrowthSize

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

Pointers to objects available for borrowing.

Definition at line 205 of file itkObjectStore.h.

◆ m_Size

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

Pointers to objects available for borrowing.

Definition at line 204 of file itkObjectStore.h.

◆ m_Store

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

A list of MemoryBlocks that have been allocated.

Definition at line 211 of file itkObjectStore.h.


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