@@ -70,18 +70,27 @@ class NodeFactory {
7070
7171 static void freeSlabs (Slab *slab);
7272
73+ #ifdef NODE_FACTORY_DEBUGGING
74+ size_t allocatedMemory = 0 ;
75+ static int nestingLevel;
76+ std::string indent () { return std::string (nestingLevel * 2 , ' ' ); }
77+ #endif
78+
7379public:
7480
7581 NodeFactory () {
7682#ifdef NODE_FACTORY_DEBUGGING
77- std::cerr << " ## New NodeFactory " << this << " \n " ;
83+ std::cerr << indent () << " ## New NodeFactory\n " ;
84+ nestingLevel++;
7885#endif
7986 }
8087
8188 virtual ~NodeFactory () {
8289 freeSlabs (CurrentSlab);
8390#ifdef NODE_FACTORY_DEBUGGING
84- std::cerr << " Delete NodeFactory " << this << " \n " ;
91+ nestingLevel--;
92+ std::cerr << indent () << " ## Delete NodeFactory: allocated memory = "
93+ << allocatedMemory << ' \n ' ;
8594#endif
8695 }
8796
@@ -92,8 +101,9 @@ class NodeFactory {
92101 size_t ObjectSize = NumObjects * sizeof (T);
93102 CurPtr = align (CurPtr, alignof (T));
94103#ifdef NODE_FACTORY_DEBUGGING
95- std::cerr << " alloc " << ObjectSize << " , CurPtr = "
104+ std::cerr << indent () << " alloc " << ObjectSize << " , CurPtr = "
96105 << (void *)CurPtr << " \n " ;
106+ allocatedMemory += ObjectSize;
97107#endif
98108
99109 // Do we have enough space in the current slab?
@@ -113,7 +123,7 @@ class NodeFactory {
113123 End = (char *)newSlab + AllocSize;
114124 assert (CurPtr + ObjectSize <= End);
115125#ifdef NODE_FACTORY_DEBUGGING
116- std::cerr << " ** new slab " << newSlab << " , allocsize = "
126+ std::cerr << indent () << " ** new slab " << newSlab << " , allocsize = "
117127 << AllocSize << " , CurPtr = " << (void *)CurPtr
118128 << " , End = " << (void *)End << " \n " ;
119129#endif
@@ -138,8 +148,8 @@ class NodeFactory {
138148 size_t AdditionalAlloc = MinGrowth * sizeof (T);
139149
140150#ifdef NODE_FACTORY_DEBUGGING
141- std::cerr << " realloc " << Objects << " , num = " << NumObjects
142- << " (size = " << OldAllocSize << " ), Growth = " << Growth
151+ std::cerr << indent () << " realloc: capacity = " << Capacity
152+ << " (size = " << OldAllocSize << " ), growth = " << MinGrowth
143153 << " (size = " << AdditionalAlloc << " )\n " ;
144154#endif
145155 if ((char *)Objects + OldAllocSize == CurPtr
@@ -149,7 +159,8 @@ class NodeFactory {
149159 CurPtr += AdditionalAlloc;
150160 Capacity += MinGrowth;
151161#ifdef NODE_FACTORY_DEBUGGING
152- std::cerr << " ** can grow: CurPtr = " << (void *)CurPtr << " \n " ;
162+ std::cerr << indent () << " ** can grow: " << (void *)CurPtr << ' \n ' ;
163+ allocatedMemory += AdditionalAlloc;
153164#endif
154165 return ;
155166 }
0 commit comments