|
@@ -4,7 +4,7 @@
|
|
|
/*
|
|
/*
|
|
|
TODO
|
|
TODO
|
|
|
- const and non-const versions of API
|
|
- const and non-const versions of API
|
|
|
- - memory pool the class construction
|
|
|
|
|
|
|
+ X memory pool the class construction
|
|
|
- attribute accessors
|
|
- attribute accessors
|
|
|
- node navigation
|
|
- node navigation
|
|
|
- handles
|
|
- handles
|
|
@@ -12,17 +12,7 @@
|
|
|
- make constructors protected
|
|
- make constructors protected
|
|
|
- hide copy constructor
|
|
- hide copy constructor
|
|
|
- hide = operator
|
|
- hide = operator
|
|
|
- - #define to remove mem-pooling, and make thread safe
|
|
|
|
|
- UTF8 support: isAlpha, etc.
|
|
- UTF8 support: isAlpha, etc.
|
|
|
-
|
|
|
|
|
- (No reason to ever cast to base)
|
|
|
|
|
- XMLBase -> Utility
|
|
|
|
|
-
|
|
|
|
|
- XMLNode
|
|
|
|
|
- Document
|
|
|
|
|
- Pooled
|
|
|
|
|
- Element
|
|
|
|
|
- Text
|
|
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
#include <limits.h>
|
|
@@ -176,7 +166,7 @@ template< int SIZE >
|
|
|
class MemPoolT : public MemPool
|
|
class MemPoolT : public MemPool
|
|
|
{
|
|
{
|
|
|
public:
|
|
public:
|
|
|
- MemPoolT() : root( 0 ), nAlloc( 0 ) {}
|
|
|
|
|
|
|
+ MemPoolT() : root(0), currentAllocs(0), nAllocs(0), maxAllocs(0) {}
|
|
|
~MemPoolT() {
|
|
~MemPoolT() {
|
|
|
// Delete the blocks.
|
|
// Delete the blocks.
|
|
|
for( int i=0; i<blockPtrs.Size(); ++i ) {
|
|
for( int i=0; i<blockPtrs.Size(); ++i ) {
|
|
@@ -185,7 +175,7 @@ public:
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
virtual int ItemSize() const { return SIZE; }
|
|
virtual int ItemSize() const { return SIZE; }
|
|
|
- int NAlloc() const { return nAlloc; }
|
|
|
|
|
|
|
+ int CurrentAllocs() const { return currentAllocs; }
|
|
|
|
|
|
|
|
virtual void* Alloc() {
|
|
virtual void* Alloc() {
|
|
|
if ( !root ) {
|
|
if ( !root ) {
|
|
@@ -201,17 +191,24 @@ public:
|
|
|
}
|
|
}
|
|
|
void* result = root;
|
|
void* result = root;
|
|
|
root = root->next;
|
|
root = root->next;
|
|
|
- ++nAlloc;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ ++currentAllocs;
|
|
|
|
|
+ if ( currentAllocs > maxAllocs ) maxAllocs = currentAllocs;
|
|
|
|
|
+ nAllocs++;
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
virtual void Free( void* mem ) {
|
|
virtual void Free( void* mem ) {
|
|
|
if ( !mem ) return;
|
|
if ( !mem ) return;
|
|
|
- --nAlloc;
|
|
|
|
|
|
|
+ --currentAllocs;
|
|
|
Chunk* chunk = (Chunk*)mem;
|
|
Chunk* chunk = (Chunk*)mem;
|
|
|
memset( chunk, 0xfe, sizeof(Chunk) );
|
|
memset( chunk, 0xfe, sizeof(Chunk) );
|
|
|
chunk->next = root;
|
|
chunk->next = root;
|
|
|
root = chunk;
|
|
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:
|
|
private:
|
|
|
enum { COUNT = 1024/SIZE };
|
|
enum { COUNT = 1024/SIZE };
|
|
@@ -224,7 +221,10 @@ private:
|
|
|
};
|
|
};
|
|
|
DynArray< Block*, 10 > blockPtrs;
|
|
DynArray< Block*, 10 > blockPtrs;
|
|
|
Chunk* root;
|
|
Chunk* root;
|
|
|
- int nAlloc;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ int currentAllocs;
|
|
|
|
|
+ int nAllocs;
|
|
|
|
|
+ int maxAllocs;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
|