You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@locus.apache.org on 2000/07/10 03:03:42 UTC

cvs commit: xml-xalan/c/src/PlatformSupport ArenaAllocator.hpp ArenaBlock.hpp ReusableArenaAllocator.hpp ReusableArenaBlock.hpp

dbertoni    00/07/09 18:03:42

  Modified:    c/src/PlatformSupport ArenaAllocator.hpp ArenaBlock.hpp
                        ReusableArenaAllocator.hpp ReusableArenaBlock.hpp
  Log:
  Modifications to use a bit map to track free blocks.
  
  Revision  Changes    Path
  1.2       +2 -2      xml-xalan/c/src/PlatformSupport/ArenaAllocator.hpp
  
  Index: ArenaAllocator.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/ArenaAllocator.hpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ArenaAllocator.hpp	2000/05/24 19:27:59	1.1
  +++ ArenaAllocator.hpp	2000/07/10 01:03:41	1.2
  @@ -70,7 +70,7 @@
   
   
   template<class Type>
  -class DeleteFunctor
  +class ArenaDeleteFunctor
   {
   public:
   
  @@ -111,7 +111,7 @@
   
   		for_each(m_blocks.begin(),
   				 m_blocks.end(),
  -				 DeleteFunctor<ArenaBlockType>());
  +				 ArenaDeleteFunctor<ArenaBlockType>());
   	}
   
   	/*
  
  
  
  1.3       +55 -6     xml-xalan/c/src/PlatformSupport/ArenaBlock.hpp
  
  Index: ArenaBlock.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/ArenaBlock.hpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ArenaBlock.hpp	2000/07/05 17:25:22	1.2
  +++ ArenaBlock.hpp	2000/07/10 01:03:41	1.3
  @@ -112,7 +112,7 @@
   		// Destroy all existing objects...
   		for_each(m_objectBlock,
   				 m_objectBlock + m_objectCount,
  -				 m_destroyFunction);
  +				 DeleteFunctor(*this, m_destroyFunction));
   
   		// Release the memory...
   		m_allocator.deallocate(m_objectBlock, 0);
  @@ -197,7 +197,56 @@
   
   protected:
   
  -	DestroyFunctionType		m_destroyFunction;
  +	virtual bool
  +	shouldDestroyBlock(const ObjectType*	/* theObject */) const
  +	{
  +		return true;
  +	}
  +
  +	size_type
  +	getBlockOffset(const ObjectType*	theObject) const
  +	{
  +		assert(ownsObject(theObject) == true);
  +
  +		return theObject - m_objectBlock;
  +	}
  +
  +	ObjectType*
  +	getBlockAddress(size_type	theOffset) const
  +	{
  +		assert(ownsObject(m_objectBlock + theOffset) == true);
  +
  +		return m_objectBlock + theOffset;
  +	}
  +
  +	struct DeleteFunctor
  +	{
  +		DeleteFunctor(
  +				const ArenaBlock&			theArenaBlock,
  +				const DestroyFunctionType&	theDestroyFunction) :
  +			m_arenaBlock(theArenaBlock),
  +			m_destroyFunction(theDestroyFunction)
  +		{
  +		}
  +
  +		void
  +		operator()(ObjectType&	theObject) const
  +		{
  +			if (m_arenaBlock.shouldDestroyBlock(&theObject) == true)
  +			{
  +				m_destroyFunction(theObject);
  +			}
  +		}
  +
  +	private:
  +
  +		const ArenaBlock&			m_arenaBlock;
  +		const DestroyFunctionType&	m_destroyFunction;
  +	};
  +
  +	friend struct DeleteFunctor;
  +
  +	const DestroyFunctionType		m_destroyFunction;
   
   private:
   
  @@ -211,13 +260,13 @@
   	operator==(const ArenaBlock&) const;
   
   	// data members...
  -	size_type			m_objectCount;
  +	size_type				m_objectCount;
   
  -	const size_type		m_blockCount;
  +	const size_type			m_blockCount;
   
  -	ObjectType*			m_objectBlock;
  +	ObjectType*				m_objectBlock;
   
  -	AllocatorType		m_allocator;
  +	AllocatorType			m_allocator;
   };
   
   
  
  
  
  1.4       +1 -4      xml-xalan/c/src/PlatformSupport/ReusableArenaAllocator.hpp
  
  Index: ReusableArenaAllocator.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/ReusableArenaAllocator.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ReusableArenaAllocator.hpp	2000/07/06 20:27:08	1.3
  +++ ReusableArenaAllocator.hpp	2000/07/10 01:03:41	1.4
  @@ -77,12 +77,9 @@
   #else
   		 class AllocatorType = std::allocator<ObjectType>,
   #endif
  -		 class ReusableDestroyFunctionType = ReusableArenaBlockDestroy<ObjectType,
  -																	   DestroyFunctionType>,
   		 class ReusableArenaBlockType = ReusableArenaBlock<ObjectType,
   														   DestroyFunctionType,
  -														   AllocatorType,
  -														   ReusableDestroyFunctionType> >
  +														   AllocatorType> >
   class ReusableArenaAllocator : public ArenaAllocator<ObjectType,
   													 DestroyFunctionType,
   													 AllocatorType,
  
  
  
  1.2       +92 -25    xml-xalan/c/src/PlatformSupport/ReusableArenaBlock.hpp
  
  Index: ReusableArenaBlock.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/ReusableArenaBlock.hpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ReusableArenaBlock.hpp	2000/05/24 19:28:00	1.1
  +++ ReusableArenaBlock.hpp	2000/07/10 01:03:41	1.2
  @@ -60,10 +60,11 @@
   
   
   
  -#include "ArenaBlock.hpp"
  +#include <PlatformSupport/XalanBitmap.hpp>
  +#include <PlatformSupport/ArenaBlock.hpp>
   
   
  -
  +#if 0
   template<class ObjectType,
   		 class DestroyFunctionType = ArenaBlockDestroy<ObjectType> >
   class ReusableArenaBlockDestroy
  @@ -147,34 +148,35 @@
   	// Destroy function to call.
   	DestroyFunctionType		m_destroyFunction;
   
  -	// Set which contains pointers to all objects
  +	// Bitmap which tracks which blocks are in use
   	// that should not be destroyed.
   	FreeListSetType			m_freeListSet;
   };
  +#endif
   
   
   
   template<class ObjectType,
   		 class DestroyFunctionType = ArenaBlockDestroy<ObjectType>,
   #if defined(XALAN_NO_NAMESPACES)
  -		 class AllocatorType = allocator<ObjectType>,
  +		 class AllocatorType = allocator<ObjectType> >
   #else
  -		 class AllocatorType = std::allocator<ObjectType>,
  +		 class AllocatorType = std::allocator<ObjectType> >
   #endif
  -		 class ReusableDestroyFunctionType = ReusableArenaBlockDestroy<ObjectType,
  -																	   DestroyFunctionType> >
   class ReusableArenaBlock : public ArenaBlock<ObjectType,
  -											 ReusableDestroyFunctionType,
  +											 DestroyFunctionType,
   											 AllocatorType>
   {
   public:
   
   	typedef ArenaBlock<ObjectType,
  -					   ReusableDestroyFunctionType,
  +					   DestroyFunctionType,
   					   AllocatorType>				BaseClassType;
   
   	ReusableArenaBlock(size_type	theBlockCount) :
  -		BaseClassType(theBlockCount)
  +		BaseClassType(theBlockCount),
  +		m_freeList(theBlockCount),
  +		m_freeListSize(0)
   	{
   	}
   
  @@ -185,50 +187,58 @@
   	virtual ObjectType*
   	allocateBlock()
   	{
  -		if (m_destroyFunction.freeListSize() == 0)
  +		if (m_freeListSize == 0)
   		{
   			return BaseClassType::allocateBlock();
   		}
   		else
   		{
  -			return m_destroyFunction.getNextFromFreeList();
  +			return getNextFromFreeList();
   		}
   	}
   
  -	// $$$ ToDo: How much error checking, etc. do we do here?  Is
  -	// it worth trying to throw exceptions when things are not
  -	// what they should be?
   	virtual void
   	commitAllocation(ObjectType*	theBlock)
   	{
   		assert(theBlock != 0);
  -		assert(m_destroyFunction.freeListSize() == 0 ||
  -			   theBlock == m_destroyFunction.getNextFromFreeList());
  +		assert(m_freeListSize == 0 ||
  +			   theBlock == getNextFromFreeList());
   
  -		if (m_destroyFunction.freeListSize() == 0)
  +		if (m_freeListSize == 0)
   		{
   			BaseClassType::commitAllocation(theBlock);
   		}
   		else
   		{
  -			m_destroyFunction.removeFromFreeList(theBlock);
  +			removeFromFreeList(theBlock);
   		}
   	}
   
   	virtual bool
   	blockAvailable() const
   	{
  -		return m_destroyFunction.freeListSize() != 0 ? true : BaseClassType::blockAvailable();
  +		return m_freeListSize != 0 ? true : BaseClassType::blockAvailable();
   	}
   
   	void
   	destroyObject(ObjectType*	theObject)
   	{
  -		if (ownsObject(theObject) == true &&
  -			m_destroyFunction.isOnFreeList(theObject) == false)
  -		{
  -			m_destroyFunction.destroyObject(theObject);
  -		}
  +		assert(ownsObject(theObject) == true &&
  +			   isOnFreeList(theObject) == false);
  +
  +		m_destroyFunction(*theObject);
  +
  +		addToFreeList(theObject);
  +	}
  +
  +protected:
  +
  +	virtual bool
  +	shouldDestroyBlock(const ObjectType*	theObject) const
  +	{
  +		assert(ownsObject(theObject) == true);
  +
  +		return !isOnFreeList(theObject);
   	}
   
   private:
  @@ -241,6 +251,63 @@
   
   	bool
   	operator==(const ReusableArenaBlock&) const;
  +
  +	bool
  +	isOnFreeList(const ObjectType*	theObject) const
  +	{
  +		assert(ownsObject(theObject) == true);
  +
  +		const size_type		theOffset =
  +				getBlockOffset(theObject);
  +
  +		return m_freeList.isSet(theOffset);
  +	}
  +
  +	void
  +	addToFreeList(const ObjectType*		theObject)
  +	{
  +		const size_type		theOffset =
  +				getBlockOffset(theObject);
  +
  +		m_freeList.set(theOffset);
  +
  +		++m_freeListSize;
  +	}
  +
  +	void
  +	removeFromFreeList(const ObjectType*	theObject)
  +	{
  +		const size_type		theOffset =
  +				getBlockOffset(theObject);
  +
  +		m_freeList.clear(theOffset);
  +
  +		--m_freeListSize;
  +	}
  +
  +	ObjectType*
  +	getNextFromFreeList()
  +	{
  +		ObjectType*		theResult = 0;
  +
  +		const unsigned long	theFreeListSize = m_freeList.getSize();
  +
  +		for(unsigned long i = 0; i < theFreeListSize; ++i)
  +		{
  +			if (m_freeList.isSet(i) == false)
  +			{
  +				theResult = getBlockAddress(i);
  +			}
  +		}
  +
  +		return theResult;
  +	}
  +
  +	// Bitmap which tracks which blocks are not in use
  +	// and that should not be destroyed.
  +	XalanBitmap		m_freeList;
  +
  +	unsigned long	m_freeListSize;
   };