You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by dm...@apache.org on 2004/11/08 19:08:51 UTC

cvs commit: xml-xalan/c/src/xalanc/Include XalanMemMgrHelper.hpp STLHelper.hpp XalanDeque.hpp XalanList.hpp XalanMap.hpp XalanMemMgrAutoPtr.hpp XalanMemMngArrayAllocate.hpp XalanMemoryManagement.hpp XalanObjectCache.hpp XalanObjectStackCache.hpp XalanSet.hpp XalanVector.hpp

dmitryh     2004/11/08 10:08:51

  Modified:    c/src/xalanc/Include STLHelper.hpp XalanDeque.hpp
                        XalanList.hpp XalanMap.hpp XalanMemMgrAutoPtr.hpp
                        XalanMemMngArrayAllocate.hpp
                        XalanMemoryManagement.hpp XalanObjectCache.hpp
                        XalanObjectStackCache.hpp XalanSet.hpp
                        XalanVector.hpp
  Added:       c/src/xalanc/Include XalanMemMgrHelper.hpp
  Log:
  Initial implementation on the pluggable memory management
  
  Revision  Changes    Path
  1.8       +45 -9     xml-xalan/c/src/xalanc/Include/STLHelper.hpp
  
  Index: STLHelper.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/Include/STLHelper.hpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- STLHelper.hpp	17 Sep 2004 22:23:10 -0000	1.7
  +++ STLHelper.hpp	8 Nov 2004 18:08:50 -0000	1.8
  @@ -55,6 +55,10 @@
   	typedef typename BaseClassType::result_type		result_type;
   	typedef typename BaseClassType::argument_type	argument_type;
   
  +    DeleteFunctor(MemoryManagerType&      theManager) :
  +        m_memoryManager(theManager)
  +    {
  +    }
   	/**
   	 * Delete the object pointed to by argument.
   	 *
  @@ -63,12 +67,18 @@
   	result_type
   	operator()(argument_type	thePointer) const
   	{
  -#if defined(XALAN_CANNOT_DELETE_CONST)
  -		delete (T*)thePointer;
  -#else
  -		delete thePointer;
  -#endif
  +        if( thePointer == 0 )
  +            return;
  +
  +		thePointer->~T();
  +        
  +        m_memoryManager.deallocate((void*)thePointer);
   	}
  +
  +private:
  +
  +   MemoryManagerType& m_memoryManager;
  +
   };
   
   
  @@ -197,6 +207,11 @@
   struct MapValueDeleteFunctor : public std::unary_function<const typename T::value_type&, void>
   #endif
   {
  +
  +    MapValueDeleteFunctor( MemoryManagerType& theManager) :
  +        m_memoryManager(theManager)
  +    {
  +    }
   #if defined(XALAN_NO_STD_NAMESPACE)
   	typedef unary_function<const typename T::value_type&, void>		BaseClassType;
   #else
  @@ -206,6 +221,13 @@
   	typedef typename BaseClassType::result_type		result_type;
   	typedef typename BaseClassType::argument_type	argument_type;
   
  +    template<class Type>
  +    static void 
  +    deletePointer(Type* ptr)
  +    {
  +        ptr->~Type();
  +    }
  +    
   	/**
   	 * Delete the value object in a map value pair.  The value of the pair must
   	 * be of pointer type.
  @@ -215,17 +237,31 @@
   	result_type
   	operator()(argument_type	thePair) const
   	{
  -		delete thePair.second;
  +        if (thePair.second != 0)
  +        {
  +            typedef typename T::value_type::second_type second_type;
  +
  +            second_type vect  =  const_cast<typename T::value_type&>(thePair).second;
  +
  +            deletePointer(vect);
  +
  +            m_memoryManager.deallocate((void*)vect);
  +
  +            thePair.second;
  +        }
   	}
  +private:
  +    MemoryManagerType& m_memoryManager;
  +
   };
   
   
   
   template<class T>
   MapValueDeleteFunctor<T>
  -makeMapValueDeleteFunctor(const T&	/* theMap */)
  +makeMapValueDeleteFunctor(const T&	 theMap)
   {
  -	return MapValueDeleteFunctor<T>();
  +	return MapValueDeleteFunctor<T>(const_cast<T&>(theMap).getMemoryManager());
   }
   
   
  @@ -428,7 +464,7 @@
   			// Delete all of the objects in the temp vector.
   			for_each(m_collection->begin(),
   					 m_collection->end(),
  -					 DeleteFunctorType());
  +					 DeleteFunctorType(m_collection->getMemoryManager()));
   		}
   	}
   
  
  
  
  1.5       +55 -25    xml-xalan/c/src/xalanc/Include/XalanDeque.hpp
  
  Index: XalanDeque.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/Include/XalanDeque.hpp,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XalanDeque.hpp	4 Nov 2004 23:11:03 -0000	1.4
  +++ XalanDeque.hpp	8 Nov 2004 18:08:50 -0000	1.5
  @@ -161,8 +161,7 @@
   {
   public:
   
  -    typedef XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager    MemoryManagerType;
  -
  + 
       typedef size_t  size_type;
   
       typedef Type            value_type;
  @@ -197,26 +196,49 @@
       typedef const_reverse_iterator_     const_reverse_iterator;
   
       XalanDeque(
  +    		MemoryManagerType& memoryManager,
               size_type initialSize = 0,
  -            MemoryManagerType* memoryManager = 0, 
               size_type blockSize = 10) :
  -        m_memoryManager(memoryManager),
  +        m_memoryManager(&memoryManager),
           m_blockSize(blockSize),
           m_blockIndex(memoryManager,
  -                    initialSize / blockSize + (initialSize % blockSize == 0 ? 0 : 1))                    
  +                    initialSize / blockSize + (initialSize % blockSize == 0 ? 0 : 1)),                    
  +        m_freeBlockVector(memoryManager)
       {
  -        XALAN_STD_QUALIFIER fill_n(XALAN_STD_QUALIFIER back_inserter(*this), initialSize, value_type());
  +        typename ConstructionTraits::Constructor::ConstructableType defaultValue(*m_memoryManager);
  +
  +        XALAN_STD_QUALIFIER fill_n(XALAN_STD_QUALIFIER back_inserter(*this), initialSize, defaultValue.value);
       }
   
  -    XalanDeque(const XalanDeque& theRhs) :
  -        m_memoryManager(theRhs.m_memoryManager),
  +    XalanDeque(const XalanDeque& theRhs, MemoryManagerType& memoryManager) :
  +        m_memoryManager(&memoryManager),
           m_blockSize(theRhs.m_blockSize),
  -        m_blockIndex(theRhs.m_memoryManager,
  -                    theRhs.size() / theRhs.m_blockSize + (theRhs.size() % theRhs.m_blockSize == 0 ? 0 : 1))
  +        m_blockIndex(*theRhs.m_memoryManager,
  +                    theRhs.size() / theRhs.m_blockSize + (theRhs.size() % theRhs.m_blockSize == 0 ? 0 : 1)),
  +        m_freeBlockVector(memoryManager)
       {
           XALAN_STD_QUALIFIER copy(theRhs.begin(), theRhs.end(), XALAN_STD_QUALIFIER back_inserter(*this));
       }
       
  +   static XalanDeque*
  +   create(
  +            MemoryManagerType&  theManager,
  +            size_type initialSize = 0,
  +            size_type blockSize = 10)
  +    {
  +        typedef XalanDeque ThisType;
  +
  +        XalanMemMgrAutoPtr<ThisType, false> theGuard( theManager , (ThisType*)theManager.allocate(sizeof(ThisType)));
  +
  +        ThisType* theResult = theGuard.get();
  +
  +        new (theResult) ThisType(theManager, initialSize, blockSize);
  +
  +        theGuard.release();
  +
  +        return theResult;
  +    }
  +     
       ~XalanDeque()
       {
           clear();
  @@ -224,7 +246,7 @@
   
           while (iter != m_freeBlockVector.end())
           {
  -            (*iter)->~XalanVector<Type>();
  +            (*iter)->~XalanVector<Type, ConstructionTraits>();
               deallocate(*iter);
               ++iter;
           }
  @@ -362,13 +384,20 @@
           theRhs.m_freeBlockVector.swap(m_freeBlockVector);
       }
   
  -    const XalanDeque & operator=(const XalanDeque & theRhs) 
  +    XalanDeque & operator=(const XalanDeque & theRhs) 
       {
           clear();
           XALAN_STD_QUALIFIER copy(theRhs.begin(), theRhs.end(), XALAN_STD_QUALIFIER back_inserter(*this));
           return *this;
       }
   
  +    MemoryManagerType&
  +    getMemoryManager()
  +    {
  +        assert (m_memoryManager != 0);
  +
  +        return *m_memoryManager;
  +    }
   protected:
   
       BlockType* getNewBlock()
  @@ -378,7 +407,7 @@
           if (m_freeBlockVector.empty())
           {
               newBlock = allocate(1);
  -            new (&*newBlock) BlockType(m_memoryManager, m_blockSize);
  +            new (&*newBlock) BlockType(*m_memoryManager, m_blockSize);
           }
           else
           {
  @@ -396,24 +425,17 @@
       {
           const size_type     theBytesNeeded = size * sizeof(BlockType);
   
  -        void*   pointer = m_memoryManager == 0 ?
  -                    ::operator new (theBytesNeeded) :
  -                                    m_memoryManager->allocate(theBytesNeeded);
  +        BlockType* pointer = (BlockType*)m_memoryManager->allocate(theBytesNeeded);
  +        
           assert(pointer != 0);
  -        return (BlockType*) pointer;
  +        
  +        return pointer;
        }
   
       void
       deallocate(BlockType*  pointer)
       {
  -        if (m_memoryManager == 0)
  -        {
  -            ::operator delete(pointer);
  -        }
  -	else
  -        {
  -            m_memoryManager->deallocate(pointer);
  -        }
  +    	m_memoryManager->deallocate(pointer);
       }
   
       BlockIndexType     m_blockIndex; 
  @@ -421,7 +443,15 @@
       
       MemoryManagerType*  m_memoryManager;
       const size_type     m_blockSize;
  +
  +private:
  +	// Not implemented
  +	XalanDeque();
  +	XalanDeque(const XalanDeque&);
  +	
   };
  +
  +
   
   XALAN_CPP_NAMESPACE_END
   
  
  
  
  1.8       +35 -24    xml-xalan/c/src/xalanc/Include/XalanList.hpp
  
  Index: XalanList.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/Include/XalanList.hpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XalanList.hpp	17 Oct 2004 00:25:58 -0000	1.7
  +++ XalanList.hpp	8 Nov 2004 18:08:50 -0000	1.8
  @@ -158,6 +158,7 @@
   {
   public:
   
  +
       typedef Type                value_type;
       typedef value_type*         pointer;
       typedef const value_type*   const_pointer;
  @@ -178,7 +179,7 @@
   			next(&nextNode) 
   		{
   		}
  -
  +	
   		value_type	value;
   		Node*		prev;
   		Node*		next;
  @@ -211,8 +212,8 @@
       typedef typename MemoryManagedConstructionTraits<value_type>::Constructor Constructor;
   
       XalanList(
  -            MemoryManagerType*  theManager = 0) :
  -        m_memoryManager(theManager),
  +            MemoryManagerType&  theManager) :
  +        m_memoryManager(&theManager),
           m_listHead(0),
   		m_freeListHeadPtr(0)
       {
  @@ -225,7 +226,7 @@
   			iterator pos = begin();
   			while (pos != end())
   			{
  -				destroyNode(pos++.node());
  +				destroyNode(pos++.node()); 
   			}
   
   			Node * freeNode = m_freeListHeadPtr;
  @@ -239,7 +240,15 @@
   			deallocate(m_listHead);
   		}
       }
  -
  +    
  +    MemoryManagerType&
  +    getMemoryManager()
  +    {
  +    	assert(m_memoryManager != 0 );
  +    	
  +        return *m_memoryManager;
  +    }
  +    
   	iterator
   	begin()
   	{
  @@ -337,6 +346,12 @@
   		erase(begin());
   	}
   
  +	void
  +	pop_back()
  +	{
  +		erase(--end());
  +	}
  +
   	iterator
   	insert(const iterator& pos, const value_type& value)
   	{
  @@ -443,13 +458,13 @@
           {
               newNode = m_freeListHeadPtr;
               nextFreeNode = m_freeListHeadPtr->next;
  -        }
  -        else
  -        {
  +		}
  +		else
  +		{
              m_freeListHeadPtr = allocate(1);
              newNode = m_freeListHeadPtr;
  -         }
  -		
  +		}
  +
           Constructor::construct(&newNode->value, data, *m_memoryManager);
           new (&newNode->prev) Node*(pos.node().prev);
           new (&newNode->next) Node*(&(pos.node()));
  @@ -458,7 +473,7 @@
   		pos.node().prev = newNode;
   		
           m_freeListHeadPtr = nextFreeNode;
  -
  +		
   		return *newNode;
   	}
   
  @@ -501,12 +516,12 @@
   	allocate(size_type  size)
   	{
   		const size_type     theBytesNeeded = size * sizeof(Node);
  +		
  +		assert(m_memoryManager != 0);
   
  -		void*   pointer = m_memoryManager == 0 ?
  -			::operator new (theBytesNeeded) :
  -			m_memoryManager->allocate(theBytesNeeded);
  +		void* pointer = m_memoryManager->allocate(theBytesNeeded);
   
  -		assert(pointer != 0);
  +		assert( pointer != 0 );
   
   		return (Node*) pointer;
   	}
  @@ -515,14 +530,9 @@
   	void
   	deallocate(Node*  pointer)
   	{
  -		if (m_memoryManager == 0)
  -		{
  -			::operator delete(pointer);
  -		}
  -		else
  -		{
  -			m_memoryManager->deallocate(pointer);
  -		}
  +		assert(m_memoryManager != 0);
  +		
  +		m_memoryManager->deallocate(pointer);
   	}
   
   	MemoryManagerType *	m_memoryManager;
  @@ -532,7 +542,8 @@
   	Node*				m_freeListHeadPtr;
   
   private:
  -
  +    // not defined
  +    XalanList();
   	XalanList(const XalanList& theRhs);
   
   	XalanList& operator=(const XalanList& theRhs);
  
  
  
  1.16      +29 -20    xml-xalan/c/src/xalanc/Include/XalanMap.hpp
  
  Index: XalanMap.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/Include/XalanMap.hpp,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- XalanMap.hpp	21 Oct 2004 23:48:27 -0000	1.15
  +++ XalanMap.hpp	8 Nov 2004 18:08:50 -0000	1.16
  @@ -30,9 +30,6 @@
   
   
   
  -#include <xalanc/Include/XalanMemoryManagement.hpp>
  -
  -
   
   #include <xalanc/Include/XalanVector.hpp>
   #include <xalanc/Include/XalanList.hpp>
  @@ -166,7 +163,7 @@
       {
       }
   
  -    XalanMapIterator(const BaseIterator& theRhs) :
  +    XalanMapIterator(const BaseIterator & theRhs) :
               BaseIterator(theRhs)
       {
       }
  @@ -234,27 +231,27 @@
       typedef typename MemoryManagedConstructionTraits<data_type>::Constructor SecondConstructor;
   
   	XalanMap(
  -			MemoryManagerType* theMemoryManager = 0,
  +			MemoryManagerType& theMemoryManager,
   			float loadFactor = 0.75,
   			size_type minBuckets = 10) :
  -		m_memoryManager(theMemoryManager),
  +		m_memoryManager(&theMemoryManager),
   		m_loadFactor(loadFactor),
   		m_minBuckets(minBuckets),
   		m_size(0),
  -		m_entries(m_memoryManager),
  -		m_buckets(m_memoryManager)
  +		m_entries(*m_memoryManager),
  +		m_buckets(*m_memoryManager)
   	{
   	}
   
   	XalanMap(
   			const XalanMap &theRhs,
  -			MemoryManagerType*  theManager = 0) :
  -        m_memoryManager(theManager != 0 ? theManager : theRhs.m_memoryManager),
  +			MemoryManagerType&  theManager) :
  +        m_memoryManager(&theManager),
   		m_loadFactor(theRhs.m_loadFactor),
   		m_minBuckets(10),
   		m_size(0),
  -		m_entries(m_memoryManager),
  -		m_buckets(size_type(m_loadFactor * theRhs.size())+ 1, m_entries.end(), m_memoryManager)
  +		m_entries(*m_memoryManager),
  +		m_buckets(size_type(m_loadFactor * theRhs.size())+ 1, m_entries.end(), theManager)
   	{
   		const_iterator entry = theRhs.begin();
   		while(entry != theRhs.end())
  @@ -266,6 +263,14 @@
   		assert(m_size == theRhs.m_size);
   	}
   
  +    MemoryManagerType&
  +    getMemoryManager()
  +    {
  +        assert (m_memoryManager != 0);
  +
  +        return *m_memoryManager;
  +    }
  +
   	~XalanMap()
   	{
           doRemoveEntries();
  @@ -273,11 +278,12 @@
   
   	XalanMap & operator=(const XalanMap& theRhs) 
   	{
  -		XalanMap theTemp(theRhs);
  +		XalanMap theTemp(theRhs, *m_memoryManager);
   		swap(theTemp);
   		return *this;
   	}
   
  +
   	size_type size() const
   	{
   		return m_size;
  @@ -477,7 +483,7 @@
   				m_buckets[index] = m_entries.end();
   			}
   		}
  -
  +        
           value_type& toRemove = *toRemovePos;
   #if defined(_MSC_VER) && _MSC_VER <= 1300
           toRemove.value_type::~value_type();
  @@ -506,11 +512,11 @@
   	void rehash()
   	{
   		// grow the number of buckets by 60%
  -		EntryPosVectorType temp(size_type(1.6 * size()), m_entries.end(), m_memoryManager);
  +		EntryPosVectorType temp(size_type(1.6 * size()), m_entries.end(), *m_memoryManager);
   		m_buckets.swap(temp);
   	
   		// move current entries into a temporary list
  -		EntryListType tempEntryList;
  +		EntryListType tempEntryList(*m_memoryManager);
   		tempEntryList.splice(tempEntryList.begin(),m_entries, m_entries.begin(), m_entries.end());
   
   		// rehash each entry assign to bucket and insert into list
  @@ -542,9 +548,9 @@
       {
           const size_type     theBytesNeeded = size * sizeof(value_type);
   
  -        void*   pointer = m_memoryManager == 0 ?
  -            ::operator new (theBytesNeeded) :
  -            m_memoryManager->allocate(theBytesNeeded);
  +        assert( m_memoryManager != 0 );
  +
  +        void*   pointer = m_memoryManager->allocate(theBytesNeeded);
   
           assert(pointer != 0);
   
  @@ -581,8 +587,11 @@
   
       EntryPosVectorType					m_buckets;
   
  +    private:
  +    // not defined
  +    XalanMap();
  +    XalanMap(const XalanMap&);
   };
  -
   
   
   XALAN_CPP_NAMESPACE_END
  
  
  
  1.4       +25 -14    xml-xalan/c/src/xalanc/Include/XalanMemMgrAutoPtr.hpp
  
  Index: XalanMemMgrAutoPtr.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/Include/XalanMemMgrAutoPtr.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XalanMemMgrAutoPtr.hpp	11 Aug 2004 13:03:59 -0000	1.3
  +++ XalanMemMgrAutoPtr.hpp	8 Nov 2004 18:08:50 -0000	1.4
  @@ -41,7 +41,7 @@
   // variations amongst the varous platforms we have to
   // support
   template<	class	Type, 
  -			bool	toCallDestructor >
  +			bool	toCallDestructor = true>
   class XalanMemMgrAutoPtr
   {
   public:
  @@ -111,9 +111,9 @@
   	
   	
   	XalanMemMgrAutoPtr(
  -			MemoryManagerType*  theManager, 
  +			MemoryManagerType&  theManager, 
   			Type* ptr  ) : 
  -		m_pointerInfo(theManager, ptr)
  +		m_pointerInfo(&theManager, ptr)
   	{
   	}	
   
  @@ -173,6 +173,14 @@
   		return MemMgrAutoPtrData(tmp);
   	}
   	
  +	Type*
  +	releasePtr()
  +	{		
  +		MemMgrAutoPtrData tmp = release();
  +	
  +		return tmp.second;
  +	}	
  +	
   	void
   	reset(	MemoryManagerType*  theManager = 0,
   			Type*		thePointer = 0 )
  @@ -236,13 +244,11 @@
   			{			
   				assert ( m_dataArray != 0 );
   
  -				Type* runPtr = m_dataArray;
  -
   				for ( size_type i = 0; i < m_size ; ++i )
   				{
  -					runPtr->~Type();
  +					m_dataArray[i].~Type();
   				}
  -				XalanMemoryManagement::deallocate ( m_dataArray, m_memoryManager );
  +				m_memoryManager->deallocate ( m_dataArray);
   			}
   		}
   		
  @@ -273,18 +279,14 @@
   		{
   			assert( isInitilized() ||
   					( (m_memoryManager == 0) && (m_dataArray ==0) && (m_size == 0)) );
  -		}
  -
  -
  -
  -		
  +		}		
   	};
   	
   	XalanMemMgrAutoPtrArray(
  -			MemoryManagerType*  theManager, 
  +			MemoryManagerType&  theManager, 
   			Type*				ptr,
   			size_type			size) : 
  -		m_pointerInfo(theManager, ptr, size)
  +		m_pointerInfo(&theManager, ptr, size)
   	{
   	}	
   
  @@ -366,6 +368,15 @@
   		m_pointerInfo.reset( 0 , 0 , 0); 
   		
   		return MemMgrAutoPtrArrayData(tmp);
  +	}
  +
  +	Type*
  +	releasePtr()
  +	{		
  +		MemMgrAutoPtrArrayData tmp = release();
  +	
  +		
  +		return tmp.dataPointer;
   	}
   	
   	void
  
  
  
  1.2       +31 -5     xml-xalan/c/src/xalanc/Include/XalanMemMngArrayAllocate.hpp
  
  Index: XalanMemMngArrayAllocate.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/Include/XalanMemMngArrayAllocate.hpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XalanMemMngArrayAllocate.hpp	11 Aug 2004 13:03:59 -0000	1.1
  +++ XalanMemMngArrayAllocate.hpp	8 Nov 2004 18:08:50 -0000	1.2
  @@ -33,14 +33,16 @@
   template <class Type>
   class XalanMemMngArrayAllocate
   {
  +    typedef typename XalanMemMgrAutoPtrArray<Type>::size_type size_type;
  +
   public:
   	static Type*
   	allocate(	size_t				size, 
  -				MemoryManagerType* 	memoryManager)
  +				MemoryManagerType& 	memoryManager)
   	{		
   		XalanMemMgrAutoPtrArray<Type> theGuard (	memoryManager,
  -													(Type*)XalanMemoryManagement::allocate( sizeof(Type)*size , memoryManager ),
  -													0 );
  +													(Type*)memoryManager.allocate( sizeof(Type)*size),
  +													size_type(size) );
   
   		size_t allocated = 0;
   
  @@ -57,11 +59,35 @@
   
   		return theResult;
   	}
  +	
  +	static Type*
  +	allocateMemMgr(	size_t				size, 
  +				MemoryManagerType& 	memoryManager)
  +	{		
  +		XalanMemMgrAutoPtrArray<Type> theGuard (	memoryManager,
  +													(Type*)memoryManager.allocate( sizeof(Type)*size),
  +													size_type(size) );
  +
  +		size_t allocated = 0;
  +
  +		for ( Type* runPtr = theGuard.get() ; allocated < size ; ++ allocated )
  +		{
  +			new ( runPtr + allocated ) Type(memoryManager);
   
  +			++theGuard;
  +		}
  +
  +		Type*  theResult = theGuard.get();
  +
  +		theGuard.release();
  +
  +		return theResult;
  +	}
  +	
   	static void
   	deallocate (	Type*				ptr,
   					size_t				size,
  -					MemoryManagerType* 	memoryManager)
  +					MemoryManagerType& 	memoryManager)
   	{
   		assert ( ptr != 0 );
   
  @@ -72,7 +98,7 @@
   			runPtr->~Type();
   		}
   
  -		XalanMemoryManagement::deallocate ( ptr, memoryManager );
  +		memoryManager.deallocate ( ptr);
   	}
    
   };
  
  
  
  1.6       +22 -10    xml-xalan/c/src/xalanc/Include/XalanMemoryManagement.hpp
  
  Index: XalanMemoryManagement.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/Include/XalanMemoryManagement.hpp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XalanMemoryManagement.hpp	4 Nov 2004 23:11:03 -0000	1.5
  +++ XalanMemoryManagement.hpp	8 Nov 2004 18:08:50 -0000	1.6
  @@ -21,26 +21,38 @@
   #include <xalanc/Include/PlatformDefinitions.hpp>
   
   #include <xercesc/framework/MemoryManager.hpp>
  -#include <xercesc/util/PlatformUtils.hpp>
   
  -#include <cassert>
  +
   
   
   XALAN_CPP_NAMESPACE_BEGIN
   
  +typedef XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager		MemoryManagerType;
  +
   
   
  -typedef XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager		MemoryManagerType;
  +class XALAN_PLATFORM_EXPORT XalanMemMgrs
  +{
  +public:
  +	
  +	static MemoryManagerType&
  +	getDummyMemMgr();
  +	
  +	
  +	static MemoryManagerType&
  +	getDefaultXercesMemMgr();
  +};
   
   template <class C>
  -struct ConstructValueWithNoMemoryManager 
  -{   
  -    ConstructValueWithNoMemoryManager(MemoryManagerType& /*mgr*/) :
  -        value()
  +class ConstructValueWithNoMemoryManager 
  +{ 
  +public:
  +    ConstructValueWithNoMemoryManager(MemoryManagerType& /*mgr*/) 
       {
       }
   
  -    const C value;
  +    C value;
  +
   };
   
   template <class C>
  @@ -51,7 +63,7 @@
       {
       }
   
  -    const C value;
  +    C value;
   };
   
   template <class C>
  @@ -73,7 +85,7 @@
   template <class C>
   struct ConstructWithMemoryManager
   {
  -    typedef ConstructValueWithNoMemoryManager<C>    ConstructableType;
  +    typedef ConstructValueWithMemoryManager<C>    ConstructableType;
   
       static C* construct(C* address, MemoryManagerType& mgr)
       {
  
  
  
  1.7       +45 -11    xml-xalan/c/src/xalanc/Include/XalanObjectCache.hpp
  
  Index: XalanObjectCache.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/Include/XalanObjectCache.hpp,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XalanObjectCache.hpp	31 Jul 2004 06:05:03 -0000	1.6
  +++ XalanObjectCache.hpp	8 Nov 2004 18:08:50 -0000	1.7
  @@ -24,7 +24,7 @@
   
   #include <xalanc/Include/XalanVector.hpp>
   #include <xalanc/Include/STLHelper.hpp>
  -#include <xalanc/Include/XalanAutoPtr.hpp>
  +
   
   
   
  @@ -38,12 +38,43 @@
   public:
   
   	ObjectType*
  -	operator()() const
  +	operator()(MemoryManagerType& theManager) const
   	{
  -		return new ObjectType;
  +        typedef ObjectType ThisType;
  +        
  +        XalanMemMgrAutoPtr<ThisType, false> theGuard( theManager , (ThisType*)theManager.allocate(sizeof(ThisType)));
  +
  +        ThisType* theResult = theGuard.get();
  +
  +        new (theResult) ThisType();
  +
  +        theGuard.release();
  +
  +        return theResult;
   	}
   };
   
  +template<class ObjectType>
  +class DefaultCacheCreateFunctorMemMgr
  +{
  +public:
  +
  +	ObjectType*
  +	operator()(MemoryManagerType& theManager) const
  +	{
  +        typedef ObjectType ThisType;
  +        
  +        XalanMemMgrAutoPtr<ThisType, false> theGuard( theManager , (ThisType*)theManager.allocate(sizeof(ThisType)));
  +
  +        ThisType* theResult = theGuard.get();
  +
  +        new (theResult) ThisType(theManager);
  +
  +        theGuard.release();
  +
  +        return theResult;
  +	}
  +};
   
   
   template<class ObjectType>
  @@ -95,9 +126,10 @@
   	typedef ObjectType	CacheObjectType;
   
   	explicit
  -	XalanObjectCache(unsigned int	initialListSize = 0) :
  -		m_availableList(),
  -		m_busyList()
  +	XalanObjectCache(MemoryManagerType& theManager,
  +                    unsigned int	initialListSize = 0) :
  +		m_availableList(theManager),
  +		m_busyList(theManager)
   	{
   		m_availableList.reserve(initialListSize);
   
  @@ -115,7 +147,7 @@
   		for_each(
   				m_availableList.begin(),
   				m_availableList.end(),
  -				m_deleteFunctor);
  +				m_deleteFunctor(theManager));
   	}
   
   	ObjectType*
  @@ -125,7 +157,7 @@
   		// that's the cheapest thing.
   		if (m_availableList.empty() == true)
   		{
  -			ObjectType* const	theNewObject = m_createFunctor();
  +			ObjectType* const	theNewObject = m_createFunctor(theManager);
   
   			m_busyList.push_back(theNewObject);
   
  @@ -237,8 +269,10 @@
   	typedef ObjectType	CacheObjectType;
   
   	explicit
  -	XalanObjectCache(unsigned int	initialListSize = 0) :
  -		m_availableList()
  +	XalanObjectCache(MemoryManagerType& theManager,
  +                    unsigned int	initialListSize = 0) :
  +        m_deleteFunctor(theManager),
  +		m_availableList(theManager)
   	{
   		m_availableList.reserve(initialListSize);
   	}
  @@ -264,7 +298,7 @@
   		// that's the cheapest thing.
   		if (m_availableList.empty() == true)
   		{
  -			return m_createFunctor();
  +			return m_createFunctor(m_availableList.getMemoryManager());
   		}
   		else
   		{
  
  
  
  1.4       +7 -3      xml-xalan/c/src/xalanc/Include/XalanObjectStackCache.hpp
  
  Index: XalanObjectStackCache.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/Include/XalanObjectStackCache.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XalanObjectStackCache.hpp	31 Jul 2004 06:05:03 -0000	1.3
  +++ XalanObjectStackCache.hpp	8 Nov 2004 18:08:50 -0000	1.4
  @@ -52,8 +52,12 @@
   	typedef ObjectType	CacheObjectType;
   
   	explicit
  -	XalanObjectStackCache(unsigned int	initialListSize = 0) :
  -		m_stack(),m_numObjectsOnStack(0)
  +	XalanObjectStackCache(MemoryManagerType& theManager, 
  +                          unsigned int	initialListSize = 0) :
  +		m_stack(theManager),
  +        m_numObjectsOnStack(0),
  +        m_createFunctor(),
  +        m_deleteFunctor(theManager)
   	{
   		m_stack.reserve(initialListSize);
   
  @@ -76,7 +80,7 @@
   		
   		if (m_stack.size() == m_numObjectsOnStack)
   		{
  -			ObjectType* const	theNewObject = m_createFunctor();
  +            ObjectType* const	theNewObject = m_createFunctor(m_stack.getMemoryManager());
   			m_stack.push_back(theNewObject);
   			++m_numObjectsOnStack;
   			return theNewObject;
  
  
  
  1.4       +14 -2     xml-xalan/c/src/xalanc/Include/XalanSet.hpp
  
  Index: XalanSet.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/Include/XalanSet.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XalanSet.hpp	17 Oct 2004 00:25:58 -0000	1.3
  +++ XalanSet.hpp	8 Nov 2004 18:08:50 -0000	1.4
  @@ -103,11 +103,23 @@
       typedef XalanSetIterator<value_type, typename SetMapType::iterator>             iterator;
       typedef XalanSetIterator<const value_type, typename SetMapType::const_iterator> const_iterator;
   
  -    XalanSet(MemoryManagerType * theMemoryManager = 0) :
  +    XalanSet(MemoryManagerType& theMemoryManager) :
           m_map(theMemoryManager)
       {
       }
   
  +    XalanSet(const XalanSet&    other,
  +             MemoryManagerType& theMemoryManager) :
  +        m_map(other.m_map, theMemoryManager)
  +    {
  +    }
  +
  +    MemoryManagerType&
  +    getMemoryManager()
  +    {
  +        return m_map.getMemoryManager();
  +    }
  +
       const_iterator begin() const
       {
           return m_map.begin();
  @@ -142,7 +154,7 @@
       void insert(const value_type& value)
       {
   	typedef typename SetMapType::value_type MapValueType;
  -        m_map.insert(MapValueType(value,true));
  +        m_map.insert(value, true);
       }
   
       size_type erase(const value_type& value)
  
  
  
  1.9       +86 -37    xml-xalan/c/src/xalanc/Include/XalanVector.hpp
  
  Index: XalanVector.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/Include/XalanVector.hpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- XalanVector.hpp	4 Nov 2004 23:11:03 -0000	1.8
  +++ XalanVector.hpp	8 Nov 2004 18:08:50 -0000	1.9
  @@ -28,6 +28,8 @@
   #include <xalanc/Include/PlatformDefinitions.hpp>
   
   
  +#include <xalanc/Include/XalanMemoryManagement.hpp>
  +
   
   #include <cstddef>
   #include <algorithm>
  @@ -38,8 +40,6 @@
   
   
   
  -#include <xalanc/Include/XalanMemoryManagement.hpp>
  -
   
   
   XALAN_CPP_NAMESPACE_BEGIN
  @@ -55,6 +55,7 @@
   {
   public:
   
  +
       typedef Type                value_type;
       typedef value_type*         pointer;
       typedef const value_type*   const_pointer;
  @@ -104,14 +105,14 @@
       typedef reverse_iterator_           reverse_iterator;
       typedef const_reverse_iterator_     const_reverse_iterator;
   
  -    typedef XalanVector<value_type>     ThisType;
  +    typedef XalanVector<value_type, ConstructionTraits>     ThisType;
   
       typedef typename ConstructionTraits::Constructor Constructor;
   
       XalanVector(
  -            MemoryManagerType*  theManager = 0,
  +            MemoryManagerType&  theManager,
               size_type           initialAllocation = size_type(0)) :
  -        m_memoryManager(theManager),
  +        m_memoryManager(&theManager),
           m_size(0),
           m_allocation(initialAllocation),
           m_data(initialAllocation > 0 ? allocate(initialAllocation) : 0)
  @@ -119,11 +120,29 @@
           invariants();
       }
   
  +    static XalanVector*
  +    create(
  +        MemoryManagerType&  theManager,
  +        size_type           initialAllocation = size_type(0))
  +    {
  +        typedef XalanVector ThisType;
  +
  +        XalanMemMgrAutoPtr<ThisType, false> theGuard( theManager , (ThisType*)theManager.allocate(sizeof(ThisType)));
  +
  +        ThisType* theResult = theGuard.get();
  +
  +        new (theResult) ThisType(theManager, initialAllocation);
  +
  +        theGuard.release();
  +
  +        return theResult;
  +    }
  +
       XalanVector(
               const ThisType&     theSource,
  -            MemoryManagerType*  theManager = 0,
  +            MemoryManagerType&  theManager,
               size_type           theInitialAllocation = size_type(0)) :
  -        m_memoryManager(theManager != 0 ? theManager : theSource.m_memoryManager),
  +        m_memoryManager(&theManager),
           m_size(0),
           m_allocation(0),
           m_data(0)
  @@ -150,8 +169,8 @@
       XalanVector(
               const_iterator      theFirst, 
               const_iterator      theLast,
  -            MemoryManagerType*  theManager = 0) :
  -        m_memoryManager(theManager),
  +            MemoryManagerType&  theManager) :
  +        m_memoryManager(&theManager),
           m_size(0),
           m_allocation(0),
           m_data(0)
  @@ -166,11 +185,29 @@
           invariants();
       }
   
  +    static XalanVector*
  +    create(           
  +            const_iterator      theFirst, 
  +            const_iterator      theLast,
  +            MemoryManagerType&  theManager)
  +    {
  +        typedef XalanVector ThisType;
  +
  +        XalanMemMgrAutoPtr<ThisType, false> theGuard( theManager , (ThisType*)theManager.allocate(sizeof(ThisType)));
  +
  +        ThisType* theResult = theGuard.get();
  +
  +        new (theResult) ThisType(theFirst, theLast, theManager);
  +
  +        theGuard.release();
  +
  +        return theResult;
  +    }
       XalanVector(
               size_type           theInsertSize,
               const value_type&   theData,
  -            MemoryManagerType*  theManager = 0) :
  -        m_memoryManager(theManager),
  +            MemoryManagerType&  theManager) :
  +        m_memoryManager(&theManager),
           m_size(0),
           m_allocation(0),
           m_data(0)
  @@ -285,7 +322,9 @@
           {
               if (theTotalSize > capacity())
               {
  -                ThisType    theTemp(m_memoryManager, theTotalSize);
  +                assert (m_memoryManager != 0);
  +
  +                ThisType    theTemp(*m_memoryManager, theTotalSize);
   
                   // insert everything up to the position...
                   theTemp.insert(theTemp.end(), begin(), thePosition);
  @@ -400,7 +439,9 @@
           {
               if (theTotalSize > capacity())
               {
  -                ThisType    theTemp(m_memoryManager, theTotalSize);
  +                assert ( m_memoryManager != 0 );
  +
  +                ThisType    theTemp(*m_memoryManager, theTotalSize);
   
                   // insert everything up to the position...
                   theTemp.insert(theTemp.end(), begin(), thePosition);
  @@ -544,14 +585,16 @@
       }
   
       void
  -    resize(
  -            size_type           theSize,
  -#if !defined(SOLARIS)  // Causes Solaris 5.3 compiler assert
  -            const value_type&   theValue = value_type()
  -#else
  -	    value_type 		theValue = value_type()
  -#endif
  -)
  +    resize(size_type   theSize)
  +    {
  +        typename ConstructionTraits::Constructor::ConstructableType defaultValue(*m_memoryManager);
  +
  +        resize(theSize , defaultValue.value);
  +    }
  +
  +    void
  +    resize( size_type           theSize,
  +            const value_type&   theValue)
       {
           invariants();
   
  @@ -729,12 +772,16 @@
       reference
       operator[](size_type    theIndex)
       {
  +        assert (theIndex < m_size);
  +
           return m_data[theIndex];
       }
   
       const_reference
       operator[](size_type    theIndex) const
       {
  +        assert (theIndex < m_size);
  +
           return m_data[theIndex];
       }
   
  @@ -761,7 +808,7 @@
           {
               if (m_allocation < theRHS.m_size)
               {
  -                ThisType    theTemp(theRHS);
  +                ThisType    theTemp(theRHS,*m_memoryManager);
   
                   swap(theTemp);
               }
  @@ -827,10 +874,12 @@
           return m_memoryManager;
       }
   
  -    MemoryManagerType*
  +    MemoryManagerType&
       getMemoryManager()
       {
  -        return m_memoryManager;
  +        assert (m_memoryManager != 0);
  +
  +        return *m_memoryManager;
       }
   
       // Detaches the allocated memory from the vector, and returns
  @@ -891,9 +940,9 @@
       {
           const size_type     theBytesNeeded = size * sizeof(value_type);
   
  -        void*   pointer = m_memoryManager == 0 ?
  -            ::operator new (theBytesNeeded) :
  -            m_memoryManager->allocate(theBytesNeeded);
  +        assert (m_memoryManager != 0);
  +
  +        void*   pointer = m_memoryManager->allocate(theBytesNeeded);
   
           assert(pointer != 0);
   
  @@ -903,14 +952,10 @@
       void
       deallocate(value_type*  pointer)
       {
  -        if (m_memoryManager == 0)
  -        {
  -            ::operator delete(pointer);
  -        }
  -        else
  -        {
  -            m_memoryManager->deallocate(pointer);
  -        }
  +        assert(m_memoryManager != 0);
  +
  +        m_memoryManager->deallocate(pointer);
  +
       }
   
       static void
  @@ -948,7 +993,7 @@
               const size_type     theNewSize = m_size == 0 ? 1 : size_type((m_size * 1.6) + 0.5);
               assert(theNewSize > m_size);
   
  -            ThisType    theTemp(*this, m_memoryManager, theNewSize);
  +            ThisType    theTemp(*this, *m_memoryManager, theNewSize);
   
               theTemp.doPushBack(data);
   
  @@ -976,7 +1021,7 @@
   
           assert(theSize > m_allocation);
   
  -        ThisType    theTemp(*this, m_memoryManager, theSize);
  +        ThisType    theTemp(*this, *m_memoryManager, theSize);
   
           swap(theTemp);
   
  @@ -1033,6 +1078,9 @@
           return theLHS > theRHS ? theLHS : theRHS;
       }
   
  +    //not implemented
  +    XalanVector(const     XalanVector&);
  +    XalanVector();
   
       // Data members...
       MemoryManagerType*  m_memoryManager;
  @@ -1141,6 +1189,7 @@
   #if defined(_MSC_VER)
   #pragma warning(pop)
   #endif
  +
   
   
   XALAN_CPP_NAMESPACE_END
  
  
  
  1.1                  xml-xalan/c/src/xalanc/Include/XalanMemMgrHelper.hpp
  
  Index: XalanMemMgrHelper.hpp
  ===================================================================
  /*
   * Copyright 1999-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  #if !defined(XALANMEMMGRHELPER_HEADER_GUARD_1357924680)
  #define XALANMEMMGRHELPER_HEADER_GUARD_1357924680
  
  
  
  // Base include file.  Must be first.
  #include <xalanc/PlatformSupport/PlatformSupportDefinitions.hpp>
  
  
  
  #include <xalanc/Include/XalanMemMgrAutoPtr.hpp>
  
  
  
  
  XALAN_CPP_NAMESPACE_BEGIN
  
  template <class Type>
  Type*
  cloneObjWithMemMgr(const Type& other, MemoryManagerType& theManager)
  {
  
      XalanMemMgrAutoPtr<Type, false> theGuard( theManager , (Type*)theManager.allocate(sizeof(Type)));
  
      Type* theResult = theGuard.get();
  
      new (theResult) Type(other, theManager);
  
      theGuard.release();
      
      return theResult;
  }
  
  
  
  template <class Type>
  Type*
  cloneObj(const Type& other, MemoryManagerType& theManager)
  {
  
      XalanMemMgrAutoPtr<Type, false> theGuard( theManager , (Type*)theManager.allocate(sizeof(Type)));
  
      Type* theResult = theGuard.get();
  
      new (theResult) Type(other);
  
      theGuard.release();
      
      return theResult;
  }
  
  template <class Type>
  class CreateObjFunctor
  {
  public:
  	Type*
  	operator()(MemoryManagerType& theManager)
  	{
  		
  		XalanMemMgrAutoPtr<Type, false> theGuard( theManager , (Type*)theManager.allocate(sizeof(Type)));
  		
  		Type* theResult = theGuard.get();
  		
  		new (theResult) Type(theManager);
  		
  		theGuard.release();
  		
  		return theResult;
  	}
  };
  
  template <class Type>
  void
  destroyObjWithMemMgr( Type* ptr, MemoryManagerType& theManager)
  {
      if( ptr == 0 )
          return;
  
      ptr->~Type();
  
      theManager.deallocate((void*)ptr);
  }
  
  
  
  XALAN_CPP_NAMESPACE_END
  
  
  
  #endif	// if !defined(XALANMEMMGRHELPER_HEADER_GUARD_1357924680)
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org