@@ -88,7 +88,6 @@ class NodeFactory {
88
88
89
89
// / Allocates an object of type T or an array of objects of type T.
90
90
template <typename T> T *Allocate (size_t NumObjects = 1 ) {
91
- static_assert (alignof (T) <= alignof (Slab *), " alignment not supported" );
92
91
size_t ObjectSize = NumObjects * sizeof (T);
93
92
CurPtr = align (CurPtr, alignof (T));
94
93
#ifdef NODE_FACTORY_DEBUGGING
@@ -100,7 +99,7 @@ class NodeFactory {
100
99
if (CurPtr + ObjectSize > End) {
101
100
// No. We have to malloc a new slab.
102
101
// We doulbe the slab size for each allocated slab.
103
- SlabSize = std::max (SlabSize * 2 , ObjectSize);
102
+ SlabSize = std::max (SlabSize * 2 , ObjectSize + alignof (T) );
104
103
size_t AllocSize = sizeof (Slab) + SlabSize;
105
104
Slab *newSlab = (Slab *)malloc (AllocSize);
106
105
@@ -109,15 +108,14 @@ class NodeFactory {
109
108
CurrentSlab = newSlab;
110
109
111
110
// Initialize the pointers to the new slab.
112
- CurPtr = ( char *)(newSlab + 1 );
113
- assert ( align (CurPtr, alignof (T)) == CurPtr) ;
114
- End = CurPtr + SlabSize ;
111
+ CurPtr = align (( char *)(newSlab + 1 ), alignof (T) );
112
+ End = ( char *)newSlab + AllocSize ;
113
+ assert ( CurPtr + ObjectSize <= End) ;
115
114
#ifdef NODE_FACTORY_DEBUGGING
116
115
std::cerr << " ** new slab " << newSlab << " , allocsize = "
117
116
<< AllocSize << " , CurPtr = " << (void *)CurPtr
118
117
<< " , End = " << (void *)End << " \n " ;
119
118
#endif
120
- assert (End == (char *)newSlab + AllocSize);
121
119
}
122
120
T *AllocatedObj = (T *)CurPtr;
123
121
CurPtr += ObjectSize;
0 commit comments