@@ -75,7 +75,9 @@ DECLARE_PERF_TIMER(MemoryPoolInitFilling)
75
75
faster to free raw DMA blocks.
76
76
@todo verify this speedup is enough to be worth the extra space
77
77
*/
78
- #define MPSB_DLINK
78
+ #ifndef DISABLE_MEMORYPOOL_MPSB_DLINK
79
+ #define MPSB_DLINK
80
+ #endif
79
81
80
82
#ifdef MEMORYPOOL_DEBUG
81
83
@@ -201,7 +203,6 @@ static Bool theMainInitFlag = false;
201
203
#define MEM_BOUND_ALIGNMENT 4
202
204
203
205
static Int roundUpMemBound (Int i);
204
- static void *sysAllocate (Int numBytes);
205
206
static void *sysAllocateDoNotZero (Int numBytes);
206
207
static void sysFree (void * p);
207
208
static void memset32 (void * ptr, Int value, Int bytesToFill);
@@ -222,27 +223,6 @@ static Int roundUpMemBound(Int i)
222
223
return (i + (MEM_BOUND_ALIGNMENT-1 )) & ~(MEM_BOUND_ALIGNMENT-1 );
223
224
}
224
225
225
- // -----------------------------------------------------------------------------
226
- /* *
227
- identical to sysAllocateDoNotZero, except that the memory block returned
228
- is filled to all-zero-bytes.
229
- */
230
- static void * sysAllocate (Int numBytes)
231
- {
232
- void * p = ::GlobalAlloc (GMEM_FIXED | GMEM_ZEROINIT, numBytes);
233
- if (!p)
234
- throw ERROR_OUT_OF_MEMORY;
235
- #ifdef MEMORYPOOL_DEBUG
236
- {
237
- USE_PERF_TIMER (MemoryPoolDebugging)
238
- theTotalSystemAllocationInBytes += ::GlobalSize (p);
239
- if (thePeakSystemAllocationInBytes < theTotalSystemAllocationInBytes)
240
- thePeakSystemAllocationInBytes = theTotalSystemAllocationInBytes;
241
- }
242
- #endif
243
- return p;
244
- }
245
-
246
226
// -----------------------------------------------------------------------------
247
227
/* *
248
228
this is the low-level allocator that we use to request memory from the OS.
@@ -837,7 +817,7 @@ Bool BlockCheckpointInfo::shouldBeInReport(Int flags, Int startCheckpoint, Int e
837
817
838
818
BlockCheckpointInfo *freed = NULL ;
839
819
try {
840
- freed = (BlockCheckpointInfo *)::sysAllocate (sizeof (BlockCheckpointInfo));
820
+ freed = (BlockCheckpointInfo *)::sysAllocateDoNotZero (sizeof (BlockCheckpointInfo));
841
821
} catch (...) {
842
822
freed = NULL ;
843
823
}
@@ -896,6 +876,7 @@ void MemoryPoolSingleBlock::initBlock(Int logicalSize, MemoryPoolBlob *owningBlo
896
876
#endif
897
877
}
898
878
#endif // MEMORYPOOL_DEBUG
879
+
899
880
#ifdef MEMORYPOOL_CHECKPOINTING
900
881
m_checkpointInfo = NULL ;
901
882
#endif
@@ -1204,7 +1185,7 @@ void MemoryPoolBlob::initBlob(MemoryPool *owningPool, Int allocationCount)
1204
1185
m_usedBlocksInBlob = 0 ;
1205
1186
1206
1187
Int rawBlockSize = MemoryPoolSingleBlock::calcRawBlockSize (m_owningPool->getAllocationSize ());
1207
- m_blockData = (char *)::sysAllocate (rawBlockSize * m_totalBlocksInBlob); // throws on failure
1188
+ m_blockData = (char *)::sysAllocateDoNotZero (rawBlockSize * m_totalBlocksInBlob); // throws on failure
1208
1189
1209
1190
// set up the list of free blocks in the blob (namely, all of 'em)
1210
1191
MemoryPoolSingleBlock *block = (MemoryPoolSingleBlock *)m_blockData;
@@ -1577,7 +1558,7 @@ MemoryPoolBlob* MemoryPool::createBlob(Int allocationCount)
1577
1558
{
1578
1559
DEBUG_ASSERTCRASH (allocationCount > 0 && allocationCount%MEM_BOUND_ALIGNMENT==0 , (" bad allocationCount (must be >0 and evenly divisible by %d)" ,MEM_BOUND_ALIGNMENT));
1579
1560
1580
- MemoryPoolBlob* blob = new (::sysAllocate (sizeof (MemoryPoolBlob))) MemoryPoolBlob; // will throw on failure
1561
+ MemoryPoolBlob* blob = new (::sysAllocateDoNotZero (sizeof (MemoryPoolBlob))) MemoryPoolBlob; // will throw on failure
1581
1562
1582
1563
blob->initBlob (this , allocationCount); // will throw on failure
1583
1564
@@ -2175,6 +2156,8 @@ void DynamicMemoryAllocator::debugIgnoreLeaksForThisBlock(void* pBlockPtr)
2175
2156
allocate a chunk-o-bytes from this DMA and return it, but don't bother zeroing
2176
2157
out the block. if unable to allocate, throw ERROR_OUT_OF_MEMORY. this
2177
2158
function will never return null.
2159
+
2160
+ added code to make sure we're on a DWord boundary, throw exception if not
2178
2161
*/
2179
2162
void *DynamicMemoryAllocator::allocateBytesDoNotZeroImplementation (Int numBytes DECLARE_LITERALSTRING_ARG2)
2180
2163
{
@@ -2262,6 +2245,13 @@ void *DynamicMemoryAllocator::allocateBytesDoNotZeroImplementation(Int numBytes
2262
2245
}
2263
2246
#endif
2264
2247
#endif
2248
+
2249
+ #if defined(RTS_DEBUG)
2250
+ // check alignment
2251
+ if (unsigned (result)&3 )
2252
+ throw ERROR_OUT_OF_MEMORY;
2253
+ #endif
2254
+
2265
2255
return result;
2266
2256
}
2267
2257
@@ -2673,7 +2663,7 @@ MemoryPool *MemoryPoolFactory::createMemoryPool(const char *poolName, Int alloca
2673
2663
throw ERROR_OUT_OF_MEMORY;
2674
2664
}
2675
2665
2676
- pool = new (::sysAllocate (sizeof (MemoryPool))) MemoryPool; // will throw on failure
2666
+ pool = new (::sysAllocateDoNotZero (sizeof (MemoryPool))) MemoryPool; // will throw on failure
2677
2667
pool->init (this , poolName, allocationSize, initialAllocationCount, overflowAllocationCount); // will throw on failure
2678
2668
2679
2669
pool->addToList (&m_firstPoolInFactory);
@@ -2689,8 +2679,7 @@ MemoryPool *MemoryPoolFactory::createMemoryPool(const char *poolName, Int alloca
2689
2679
*/
2690
2680
MemoryPool *MemoryPoolFactory::findMemoryPool (const char *poolName)
2691
2681
{
2692
- MemoryPool *pool = m_firstPoolInFactory;
2693
- for (; pool; pool = pool->getNextPoolInList ())
2682
+ for (MemoryPool *pool = m_firstPoolInFactory; pool; pool = pool->getNextPoolInList ())
2694
2683
{
2695
2684
if (!strcmp (poolName, pool->getPoolName ()))
2696
2685
{
@@ -2729,7 +2718,7 @@ DynamicMemoryAllocator *MemoryPoolFactory::createDynamicMemoryAllocator(Int numS
2729
2718
{
2730
2719
DynamicMemoryAllocator *dma;
2731
2720
2732
- dma = new (::sysAllocate (sizeof (DynamicMemoryAllocator))) DynamicMemoryAllocator; // will throw on failure
2721
+ dma = new (::sysAllocateDoNotZero (sizeof (DynamicMemoryAllocator))) DynamicMemoryAllocator; // will throw on failure
2733
2722
dma->init (this , numSubPools, pParms); // will throw on failure
2734
2723
2735
2724
dma->addToList (&m_firstDmaInFactory);
@@ -3424,7 +3413,7 @@ void initMemoryManager()
3424
3413
Int numSubPools;
3425
3414
const PoolInitRec *pParms;
3426
3415
userMemoryManagerGetDmaParms (&numSubPools, &pParms);
3427
- TheMemoryPoolFactory = new (::sysAllocate (sizeof (MemoryPoolFactory))) MemoryPoolFactory; // will throw on failure
3416
+ TheMemoryPoolFactory = new (::sysAllocateDoNotZero (sizeof (MemoryPoolFactory))) MemoryPoolFactory; // will throw on failure
3428
3417
TheMemoryPoolFactory->init (); // will throw on failure
3429
3418
TheDynamicMemoryAllocator = TheMemoryPoolFactory->createDynamicMemoryAllocator (numSubPools, pParms); // will throw on failure
3430
3419
userMemoryManagerInitPools ();
@@ -3499,7 +3488,7 @@ static void preMainInitMemoryManager()
3499
3488
Int numSubPools;
3500
3489
const PoolInitRec *pParms;
3501
3490
userMemoryManagerGetDmaParms (&numSubPools, &pParms);
3502
- TheMemoryPoolFactory = new (::sysAllocate (sizeof (MemoryPoolFactory))) MemoryPoolFactory; // will throw on failure
3491
+ TheMemoryPoolFactory = new (::sysAllocateDoNotZero (sizeof (MemoryPoolFactory))) MemoryPoolFactory; // will throw on failure
3503
3492
TheMemoryPoolFactory->init (); // will throw on failure
3504
3493
3505
3494
TheDynamicMemoryAllocator = TheMemoryPoolFactory->createDynamicMemoryAllocator (numSubPools, pParms); // will throw on failure
0 commit comments