18 #if !defined(XALAN_OBJECTCACHE_HEADER_GUARD)
19 #define XALAN_OBJECTCACHE_HEADER_GUARD
37 template<
class ObjectType>
45 typedef ObjectType ThisType;
49 ThisType*
const theResult =
50 new (theGuard.
get()) ThisType();
60 template<
class ObjectType>
68 typedef ObjectType ThisType;
72 ThisType*
const theResult =
73 new (theGuard.
get()) ThisType(theManager);
83 template<
class ObjectType>
96 template<
class ObjectType>
104 theInstance->clear();
110 #if defined(XALAN_OBJECT_CACHE_KEEP_BUSY_LIST)
114 #if defined(XALAN_NO_DEFAULT_TEMPLATE_ARGUMENTS)
115 class CreateFunctorType,
116 class DeleteFunctorType,
117 class ResetFunctorType>
119 class CreateFunctorType = DefaultCacheCreateFunctor<ObjectType>,
120 class DeleteFunctorType = DeleteFunctor<ObjectType>,
121 class ResetFunctorType = DefaultCacheResetFunctor<ObjectType> >
123 class XalanObjectCache
127 typedef XalanVector<ObjectType*> VectorType;
129 typedef ObjectType CacheObjectType;
133 MemoryManager& theManager,
134 XalanSize_t initialListSize = 0) :
135 m_availableList(theManager),
136 m_busyList(theManager)
138 m_availableList.reserve(initialListSize);
140 m_busyList.reserve(initialListSize);
150 m_availableList.begin(),
151 m_availableList.end(),
152 m_deleteFunctor(theManager));
160 if (m_availableList.empty() ==
true)
162 ObjectType*
const theNewObject = m_createFunctor(m_availableList.getMemoryManager());
164 m_busyList.push_back(theNewObject);
170 ObjectType*
const theObject = m_availableList.back();
172 m_busyList.push_back(theObject);
174 m_availableList.pop_back();
181 release(ObjectType* theInstance)
185 typedef typename VectorType::iterator IteratorType;
187 const IteratorType i =
193 if (i == m_busyList.end())
199 m_resetFunctor(theInstance);
201 m_availableList.push_back(theInstance);
212 while (m_busyList.empty() ==
false)
214 ObjectType*
const theInstance = m_busyList.back();
216 m_resetFunctor(theInstance);
218 m_availableList.push_back(theInstance);
220 m_busyList.pop_back();
225 CreateFunctorType m_createFunctor;
227 DeleteFunctorType m_deleteFunctor;
229 ResetFunctorType m_resetFunctor;
234 XalanObjectCache(
const XalanObjectCache<ObjectType, CreateFunctorType, DeleteFunctorType, ResetFunctorType>& theRHS);
236 XalanObjectCache<ObjectType, CreateFunctorType, DeleteFunctorType, ResetFunctorType>&
237 operator=(
const XalanObjectCache<ObjectType, CreateFunctorType, DeleteFunctorType, ResetFunctorType>& theRHS);
241 VectorType m_availableList;
243 VectorType m_busyList;
254 #if defined(XALAN_NO_DEFAULT_TEMPLATE_ARGUMENTS)
255 class CreateFunctorType,
256 class DeleteFunctorType,
257 class ResetFunctorType>
259 class CreateFunctorType = DefaultCacheCreateFunctor<ObjectType>,
260 class DeleteFunctorType = DeleteFunctor<ObjectType>,
261 class ResetFunctorType = DefaultCacheResetFunctor<ObjectType> >
273 XalanSize_t initialListSize = 0) :
274 m_deleteFunctor(theManager),
275 m_availableList(theManager)
277 m_availableList.reserve(initialListSize);
287 m_availableList.begin(),
288 m_availableList.end(),
297 if (m_availableList.empty() ==
true)
299 return m_createFunctor(m_availableList.getMemoryManager());
303 ObjectType*
const theObject = m_availableList.back();
305 m_availableList.pop_back();
314 m_resetFunctor(theInstance);
316 m_availableList.push_back(theInstance);
352 template<
class XalanObjectCacheType>
361 m_cachedObject(theCache.get())
367 if (m_cachedObject != 0)
369 m_cache.release(m_cachedObject);
376 return m_cachedObject;
396 XalanObjectCacheType& m_cache;
398 CacheObjectType* m_cachedObject;
403 template<
class ObjectType>
407 DefaultCacheCreateFunctor<ObjectType>,
408 DeleteFunctor<ObjectType>,
409 DefaultCacheResetFunctor<ObjectType> >
421 MemoryManager& theManager,
422 XalanSize_t initialListSize = 0) :
430 template<
class ObjectType>
434 DefaultCacheCreateFunctorMemMgr<ObjectType>,
435 DeleteFunctor<ObjectType>,
436 DefaultCacheResetFunctor<ObjectType> >
448 MemoryManager& theManager,
449 XalanSize_t initialListSize = 0) :