Frobby  0.9.5
Public Member Functions | Private Attributes | List of all members
ObjectCache< T > Class Template Reference

An ObjectCache keeps a cache of previously-used objects to cut down on the number of allocations. More...

#include <ObjectCache.h>

Public Member Functions

 ObjectCache ()
 
auto_ptr< T > newObject ()
 Returns an object. More...
 
template<class S >
auto_ptr< T > newObjectCopy (const S &copyOf)
 Returns a copy of copyOf. More...
 
template<class S >
void freeObject (auto_ptr< S > object)
 Insert an object into the cache. More...
 

Private Attributes

vector< T * > _cache
 
ElementDeleter< vector< T * > > _cacheDeleter
 

Detailed Description

template<class T>
class ObjectCache< T >

An ObjectCache keeps a cache of previously-used objects to cut down on the number of allocations.

The cache accepts unused objects that would otherwise be due for deallocation, and returns them in place of a new object when asked for one. If the cache is asked for an object and it is not storing any, it will transparently allocate one to satisfy the request. Stored objects are not freed until the cache is destructed.

Definition at line 35 of file ObjectCache.h.

Constructor & Destructor Documentation

◆ ObjectCache()

template<class T >
ObjectCache< T >::ObjectCache
inline

Definition at line 63 of file ObjectCache.h.

Member Function Documentation

◆ freeObject()

template<class T >
template<class S >
void ObjectCache< T >::freeObject ( auto_ptr< S >  object)

Insert an object into the cache.

Definition at line 90 of file ObjectCache.h.

◆ newObject()

template<class T >
auto_ptr< T > ObjectCache< T >::newObject

Returns an object.

The new object is constructed using the standard constructor, or it is an object previously passed to freeObject().

Definition at line 69 of file ObjectCache.h.

◆ newObjectCopy()

template<class T >
template<class S >
auto_ptr< T > ObjectCache< T >::newObjectCopy ( const S &  copyOf)

Returns a copy of copyOf.

The new object is constructed using the copy constructor, or it is an object previously passed to freeObject() that has copyOf assigned to it.

Definition at line 79 of file ObjectCache.h.

Member Data Documentation

◆ _cache

template<class T >
vector<T*> ObjectCache< T >::_cache
private

Definition at line 56 of file ObjectCache.h.

◆ _cacheDeleter

template<class T >
ElementDeleter<vector<T*> > ObjectCache< T >::_cacheDeleter
private

Definition at line 57 of file ObjectCache.h.


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