Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itk::ObjectStore< TObjectType > Class Template Reference

A specialized memory management object for allocating and destroying contiguous blocks of objects. More...

#include <itkObjectStore.h>

Inheritance diagram for itk::ObjectStore< TObjectType >:

Inheritance graph
[legend]
Collaboration diagram for itk::ObjectStore< TObjectType >:

Collaboration graph
[legend]
List of all members.

Public Types

typedef ObjectStore Self
typedef Object Superclass
typedef SmartPointer< SelfPointer
typedef SmartPointer< const
Self
ConstPointer
typedef TObjectType ObjectType
typedef std::vector< ObjectType * > FreeListType
enum  GrowthStrategyType { LINEAR_GROWTH = 0, EXPONENTIAL_GROWTH = 1 }

Public Member Functions

virtual const char * GetNameOfClass () const
ObjectTypeBorrow ()
void Return (ObjectType *p)
virtual::vcl_size_t GetSize ()
void Reserve (::vcl_size_t n)
void Squeeze ()
void Clear ()
void SetGrowthStrategyToExponential ()
void SetGrowthStrategyToLinear ()
virtual void SetLinearGrowthSize (::vcl_size_t _arg)
virtual::vcl_size_t GetLinearGrowthSize ()
virtual void SetGrowthStrategy (GrowthStrategyType _arg)
virtual GrowthStrategyType GetGrowthStrategy ()

Static Public Member Functions

Pointer New ()

Protected Member Functions

 ObjectStore ()
 ~ObjectStore ()
virtual void PrintSelf (std::ostream &os, Indent indent) const
::vcl_size_t GetGrowthSize ()

Detailed Description

template<class 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.

Warnings: 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 60 of file itkObjectStore.h.


Member Typedef Documentation

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

Reimplemented from itk::Object.

Definition at line 67 of file itkObjectStore.h.

template<class TObjectType>
typedef std::vector<ObjectType *> itk::ObjectStore< TObjectType >::FreeListType
 

Type of list for storing pointers to free memory.

Definition at line 79 of file itkObjectStore.h.

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

Type of the objects in storage.

Definition at line 76 of file itkObjectStore.h.

Referenced by itk::ObjectStore< TObjectType >::MemoryBlock::Delete(), and itk::ObjectStore< TObjectType >::MemoryBlock::MemoryBlock().

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

Reimplemented from itk::Object.

Definition at line 66 of file itkObjectStore.h.

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

Standard typedefs.

Reimplemented from itk::Object.

Definition at line 64 of file itkObjectStore.h.

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

Reimplemented from itk::Object.

Definition at line 65 of file itkObjectStore.h.


Member Enumeration Documentation

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

Type of memory allocation strategy

Enumeration values:
LINEAR_GROWTH 
EXPONENTIAL_GROWTH 

Definition at line 82 of file itkObjectStore.h.


Constructor & Destructor Documentation

template<class TObjectType>
itk::ObjectStore< TObjectType >::ObjectStore  )  [protected]
 

template<class TObjectType>
itk::ObjectStore< TObjectType >::~ObjectStore  )  [protected]
 


Member Function Documentation

template<class TObjectType>
ObjectType* itk::ObjectStore< TObjectType >::Borrow  ) 
 

Borrow a pointer to an object from the memory store.

template<class TObjectType>
void itk::ObjectStore< TObjectType >::Clear  ) 
 

Frees all memory in the container

template<class TObjectType>
:: vcl_size_t itk::ObjectStore< TObjectType >::GetGrowthSize  )  [protected]
 

Returns a new size to grow.

template<class TObjectType>
virtual GrowthStrategyType itk::ObjectStore< TObjectType >::GetGrowthStrategy  )  [virtual]
 

Set/Get the growth strategy.

template<class TObjectType>
virtual :: vcl_size_t itk::ObjectStore< TObjectType >::GetLinearGrowthSize  ) 
 

Set/Get the linear growth size

template<class TObjectType>
virtual const char* itk::ObjectStore< TObjectType >::GetNameOfClass  )  const [virtual]
 

Run-time type information (and related methods).

Reimplemented from itk::Object.

template<class TObjectType>
virtual :: vcl_size_t itk::ObjectStore< TObjectType >::GetSize  ) 
 

Returns the size of the container. This is not the number of objects available, but the total number of objects allocated.

template<class TObjectType>
Pointer itk::ObjectStore< TObjectType >::New  )  [static]
 

Method for creation through the object factory.

Reimplemented from itk::Object.

template<class TObjectType>
virtual void itk::ObjectStore< TObjectType >::PrintSelf std::ostream &  os,
Indent  indent
const [protected, virtual]
 

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<class TObjectType>
void itk::ObjectStore< TObjectType >::Reserve ::vcl_size_t  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<class 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<class TObjectType>
virtual void itk::ObjectStore< TObjectType >::SetGrowthStrategy GrowthStrategyType  _arg  )  [virtual]
 

Set/Get the growth strategy.

template<class TObjectType>
void itk::ObjectStore< TObjectType >::SetGrowthStrategyToExponential  )  [inline]
 

Set growth strategy to exponential

Definition at line 119 of file itkObjectStore.h.

template<class TObjectType>
void itk::ObjectStore< TObjectType >::SetGrowthStrategyToLinear  )  [inline]
 

Set growth strategy to linear

Definition at line 123 of file itkObjectStore.h.

template<class TObjectType>
virtual void itk::ObjectStore< TObjectType >::SetLinearGrowthSize ::vcl_size_t  _arg  )  [virtual]
 

Set/Get the linear growth size

template<class 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.


The documentation for this class was generated from the following file:
Generated at Thu May 25 01:59:29 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000