@@ -70,18 +70,27 @@ class NodeFactory {
70
70
71
71
static void freeSlabs (Slab *slab);
72
72
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
+
73
79
public:
74
80
75
81
NodeFactory () {
76
82
#ifdef NODE_FACTORY_DEBUGGING
77
- std::cerr << " ## New NodeFactory " << this << " \n " ;
83
+ std::cerr << indent () << " ## New NodeFactory\n " ;
84
+ nestingLevel++;
78
85
#endif
79
86
}
80
87
81
88
virtual ~NodeFactory () {
82
89
freeSlabs (CurrentSlab);
83
90
#ifdef NODE_FACTORY_DEBUGGING
84
- std::cerr << " Delete NodeFactory " << this << " \n " ;
91
+ nestingLevel--;
92
+ std::cerr << indent () << " ## Delete NodeFactory: allocated memory = "
93
+ << allocatedMemory << ' \n ' ;
85
94
#endif
86
95
}
87
96
@@ -92,8 +101,9 @@ class NodeFactory {
92
101
size_t ObjectSize = NumObjects * sizeof (T);
93
102
CurPtr = align (CurPtr, alignof (T));
94
103
#ifdef NODE_FACTORY_DEBUGGING
95
- std::cerr << " alloc " << ObjectSize << " , CurPtr = "
104
+ std::cerr << indent () << " alloc " << ObjectSize << " , CurPtr = "
96
105
<< (void *)CurPtr << " \n " ;
106
+ allocatedMemory += ObjectSize;
97
107
#endif
98
108
99
109
// Do we have enough space in the current slab?
@@ -113,7 +123,7 @@ class NodeFactory {
113
123
End = (char *)newSlab + AllocSize;
114
124
assert (CurPtr + ObjectSize <= End);
115
125
#ifdef NODE_FACTORY_DEBUGGING
116
- std::cerr << " ** new slab " << newSlab << " , allocsize = "
126
+ std::cerr << indent () << " ** new slab " << newSlab << " , allocsize = "
117
127
<< AllocSize << " , CurPtr = " << (void *)CurPtr
118
128
<< " , End = " << (void *)End << " \n " ;
119
129
#endif
@@ -138,8 +148,8 @@ class NodeFactory {
138
148
size_t AdditionalAlloc = MinGrowth * sizeof (T);
139
149
140
150
#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
143
153
<< " (size = " << AdditionalAlloc << " )\n " ;
144
154
#endif
145
155
if ((char *)Objects + OldAllocSize == CurPtr
@@ -149,7 +159,8 @@ class NodeFactory {
149
159
CurPtr += AdditionalAlloc;
150
160
Capacity += MinGrowth;
151
161
#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;
153
164
#endif
154
165
return ;
155
166
}
0 commit comments