memory tracking

This commit is contained in:
Lee Thomason 2012-02-13 18:11:20 -08:00
parent 50adb4ca8e
commit e9ecdabf94
2 changed files with 31 additions and 53 deletions

View File

@ -58,7 +58,7 @@ const char* StrPair::GetStr()
else {
++p;
}
*q = LF;
*q++ = LF;
}
else if ( (flags & NEEDS_NEWLINE_NORMALIZATION) && *p == LF ) {
if ( *(p+1) == CR ) {
@ -67,7 +67,7 @@ const char* StrPair::GetStr()
else {
++p;
}
*q = LF;
*q++ = LF;
}
else if ( (flags & NEEDS_ENTITY_PROCESSING) && *p == '&' ) {
int i=0;
@ -275,11 +275,9 @@ bool XMLDocument::Accept( XMLVisitor* visitor ) const
XMLNode::XMLNode( XMLDocument* doc ) :
document( doc ),
parent( 0 ),
// isTextParent( false ),
firstChild( 0 ), lastChild( 0 ),
prev( 0 ), next( 0 )
{
}
@ -342,9 +340,6 @@ XMLNode* XMLNode::InsertEndChild( XMLNode* addThis )
addThis->prev = 0;
addThis->next = 0;
}
// if ( addThis->ToText() ) {
// SetTextParent();
// }
return addThis;
}
@ -384,15 +379,6 @@ void XMLNode::DeleteChild( XMLNode* node )
}
/*void XMLNode::Print( XMLStreamer* streamer )
{
for( XMLNode* node = firstChild; node; node=node->next ) {
node->Print( streamer );
}
}
*/
char* XMLNode::ParseDeep( char* p )
{
while( p && *p ) {
@ -524,14 +510,6 @@ char* XMLAttribute::ParseDeep( char* p )
}
/*
void XMLAttribute::Print( XMLStreamer* streamer )
{
// fixme: sort out single vs. double quote
//fprintf( cfile, "%s=\"%s\"", name.GetStr(), value.GetStr() );
streamer->PushAttribute( name.GetStr(), value.GetStr() );
}
*/
// --------- XMLElement ---------- //
XMLElement::XMLElement( XMLDocument* doc ) : XMLNode( doc ),
@ -544,8 +522,6 @@ XMLElement::XMLElement( XMLDocument* doc ) : XMLNode( doc ),
XMLElement::~XMLElement()
{
//printf( "~XMLElemen %x\n",this );
XMLAttribute* attribute = rootAttribute;
while( attribute ) {
XMLAttribute* next = attribute->next;
@ -643,29 +619,6 @@ char* XMLElement::ParseDeep( char* p )
}
/*
void XMLElement::Print( XMLStreamer* streamer )
{
//if ( !parent || !parent->IsTextParent() ) {
// PrintSpace( cfile, depth );
//}
//fprintf( cfile, "<%s", Name() );
streamer->OpenElement( Name() );
for( XMLAttribute* attrib=rootAttribute; attrib; attrib=attrib->next ) {
//fprintf( cfile, " " );
attrib->Print( streamer );
}
for( XMLNode* node=firstChild; node; node=node->next ) {
node->Print( streamer );
}
streamer->CloseElement();
}
*/
bool XMLElement::Accept( XMLVisitor* visitor ) const
{
if ( visitor->VisitEnter( *this, rootAttribute ) )
@ -695,12 +648,13 @@ XMLDocument::~XMLDocument()
ClearChildren();
delete [] charBuffer;
/*
#if 1
textPool.Trace( "text" );
elementPool.Trace( "element" );
commentPool.Trace( "comment" );
attributePool.Trace( "attribute" );
*/
#endif
TIXMLASSERT( textPool.CurrentAllocs() == 0 );
TIXMLASSERT( elementPool.CurrentAllocs() == 0 );
TIXMLASSERT( commentPool.CurrentAllocs() == 0 );

View File

@ -3,11 +3,21 @@
#include <stdio.h>
#include <stdlib.h>
#if defined( WIN32 )
#include <crtdbg.h>
_CrtMemState startMemState;
_CrtMemState endMemState;
#endif
using namespace tinyxml2;
int main( int argc, const char* argv )
{
#if 1
#if defined( WIN32 )
_CrtMemCheckpoint( &startMemState );
#endif
#if 0
{
static const char* test = "<!--hello world\n"
" line 2\r"
@ -47,7 +57,7 @@ int main( int argc, const char* argv )
}
}
#endif
#if 1
#if 0
{
static const char* test = "<element>Text before.</element>";
XMLDocument doc;
@ -64,5 +74,19 @@ int main( int argc, const char* argv )
delete doc;
}
#endif
{
XMLDocument* doc = new XMLDocument();
doc->InsertEndChild( doc->NewElement( "element" ) );
doc->Print();
delete doc;
}
#if defined( WIN32 )
_CrtMemCheckpoint( &endMemState );
//_CrtMemDumpStatistics( &endMemState );
_CrtMemState diffMemState;
_CrtMemDifference( &diffMemState, &startMemState, &endMemState );
_CrtMemDumpStatistics( &diffMemState );
#endif
return 0;
}