#include <itkObjectStore.h>
Inheritance diagram for itk::ObjectStore< TObjectType >:
Public Types | |
typedef ObjectStore | Self |
typedef Object | Superclass |
typedef SmartPointer< Self > | Pointer |
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 |
ObjectType * | Borrow () |
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 () |
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.
|
Reimplemented from itk::Object. Definition at line 67 of file itkObjectStore.h. |
|
Type of list for storing pointers to free memory. Definition at line 79 of file itkObjectStore.h. |
|
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(). |
|
Reimplemented from itk::Object. Definition at line 66 of file itkObjectStore.h. |
|
Standard typedefs. Reimplemented from itk::Object. Definition at line 64 of file itkObjectStore.h. |
|
Reimplemented from itk::Object. Definition at line 65 of file itkObjectStore.h. |
|
Type of memory allocation strategy Definition at line 82 of file itkObjectStore.h. |
|
|
|
|
|
Borrow a pointer to an object from the memory store. |
|
Frees all memory in the container |
|
Returns a new size to grow. |
|
Set/Get the growth strategy. |
|
Set/Get the linear growth size |
|
Run-time type information (and related methods). Reimplemented from itk::Object. |
|
Returns the size of the container. This is not the number of objects available, but the total number of objects allocated. |
|
Method for creation through the object factory. Reimplemented from itk::Object. |
|
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. |
|
Ensures that there are at least n elements allocated in the storage container. Will not shrink the container, but may enlarge the container. |
|
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. |
|
Set/Get the growth strategy. |
|
Set growth strategy to exponential Definition at line 119 of file itkObjectStore.h. |
|
Set growth strategy to linear Definition at line 123 of file itkObjectStore.h. |
|
Set/Get the linear growth size |
|
Attempts to free memory that is not in use and shrink the size of the container. Not guaranteed to do anything. |