diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 65f2689..829ef17 100644 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -572,10 +572,16 @@ XMLDocument::~XMLDocument() ClearChildren(); delete [] charBuffer; - TIXMLASSERT( textPool.NAlloc() == 0 ); - TIXMLASSERT( elementPool.NAlloc() == 0 ); - TIXMLASSERT( commentPool.NAlloc() == 0 ); - TIXMLASSERT( attributePool.NAlloc() == 0 ); + /* + textPool.Trace( "text" ); + elementPool.Trace( "element" ); + commentPool.Trace( "comment" ); + attributePool.Trace( "attribute" ); + */ + TIXMLASSERT( textPool.CurrentAllocs() == 0 ); + TIXMLASSERT( elementPool.CurrentAllocs() == 0 ); + TIXMLASSERT( commentPool.CurrentAllocs() == 0 ); + TIXMLASSERT( attributePool.CurrentAllocs() == 0 ); } diff --git a/tinyxml2.h b/tinyxml2.h index 1f4d719..f024647 100644 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -4,7 +4,7 @@ /* TODO - const and non-const versions of API - - memory pool the class construction + X memory pool the class construction - attribute accessors - node navigation - handles @@ -12,17 +12,7 @@ - make constructors protected - hide copy constructor - hide = operator - - #define to remove mem-pooling, and make thread safe - UTF8 support: isAlpha, etc. - - (No reason to ever cast to base) - XMLBase -> Utility - - XMLNode - Document - Pooled - Element - Text */ #include @@ -176,7 +166,7 @@ template< int SIZE > class MemPoolT : public MemPool { public: - MemPoolT() : root( 0 ), nAlloc( 0 ) {} + MemPoolT() : root(0), currentAllocs(0), nAllocs(0), maxAllocs(0) {} ~MemPoolT() { // Delete the blocks. for( int i=0; inext; - ++nAlloc; + + ++currentAllocs; + if ( currentAllocs > maxAllocs ) maxAllocs = currentAllocs; + nAllocs++; return result; } virtual void Free( void* mem ) { if ( !mem ) return; - --nAlloc; + --currentAllocs; Chunk* chunk = (Chunk*)mem; memset( chunk, 0xfe, sizeof(Chunk) ); chunk->next = root; root = chunk; } + void Trace( const char* name ) { + printf( "Mempool %s watermark=%d current=%d size=%d nAlloc=%d blocks=%d\n", + name, maxAllocs, currentAllocs, SIZE, nAllocs, blockPtrs.Size() ); + } private: enum { COUNT = 1024/SIZE }; @@ -224,7 +221,10 @@ private: }; DynArray< Block*, 10 > blockPtrs; Chunk* root; - int nAlloc; + + int currentAllocs; + int nAllocs; + int maxAllocs; };