Merging in sfraser's MacMemAllocator changes from 4.5, along with improved MacMemAllocator/cache behavior.

This commit is contained in:
saari%netscape.com 1998-08-04 21:50:56 +00:00
parent faeb2e1fc8
commit bb35a39676
2 changed files with 85 additions and 71 deletions

View File

@ -537,6 +537,17 @@ void CallPreAllocators(void)
static MemoryCacheFlusherProc sGarbageCollectorCacheFlusher = NULL;
/* CallCacheFlushers is only called under extreme conditions now, when an attempt to
allocate a new sub-heap has failed.
The flush procs called here are set up in fredmem.cp:
InstallMemoryCacheFlusher(&ImageCacheMemoryFlusher);
InstallMemoryCacheFlusher(&NetlibCacheMemoryFlusher);
InstallMemoryCacheFlusher(&LayoutCacheMemoryFlusher);
InstallMemoryCacheFlusher(&LibNeoCacheMemoryFlusher);
*/
UInt8 CallCacheFlushers(size_t blockSize)
{
MemoryCacheFlusherProcRec *currentCacheFlusher = gFirstFlusher;
@ -544,7 +555,8 @@ UInt8 CallCacheFlushers(size_t blockSize)
// we might want to remember which flusher was called last and start
// at the one after, to avoid always flushing the first one (image cache)
// first.
// first. But since this is a last-ditch effort to free memory, that's
// probably not worth it.
while (currentCacheFlusher != NULL)
{
@ -628,7 +640,7 @@ SubHeapAllocationChunk * AllocateSubHeap ( SubHeapAllocationRoot * root, Size he
if ( heapBlock != NULL )
{
heapBlock->root = root;
heapBlock->refCon = tempHandle;
heapBlock->refCon = tempHandle; // so we can dispose the handle when we're done with the subheap
heapBlock->next = NULL;
heapBlock->usedBlocks = 0;
heapBlock->freeDescriptor.freeRoutine = NULL;

View File

@ -295,26 +295,29 @@ void *malloc(size_t blockSize)
if ( newBlock == NULL )
{
/* we need to ensure no one else tries to flush cache's while we do */
/* if we don't have it, try allocating a new chunk */
if ( (whichAllocator->chunkAllocRoutine)( blockSize, whichAllocator->root ) != NULL )
{
newBlock = (char *)(whichAllocator->blockAllocRoutine)(blockSize, whichAllocator->root);
}
else
{
/* We're in deep doo-doo. We failed to allocate a new sub-heap, so let's */
/* flush everything that we can. */
/* We need to ensure no one else tries to flush cache's while we do */
/* This may mean that we allocate temp mem while flushing the cache that we would */
/* have had space for after the flush, but life sucks... */
if ( gInsideCacheFlush == false )
{
/* we didn't get it. Flush some caches and try again */
/* Flush some caches and try again */
gInsideCacheFlush = true;
CallCacheFlushers ( blockSize );
gInsideCacheFlush = false;
/* We may have freed up some space, so let's try allocating again */
newBlock = (char *)(whichAllocator->blockAllocRoutine)(blockSize, whichAllocator->root);
}
/* if we still don't have it, try allocating a new chunk */
if ( newBlock == NULL )
{
if ( (whichAllocator->chunkAllocRoutine)( blockSize, whichAllocator->root ) != NULL )
{
newBlock = (char *)(whichAllocator->blockAllocRoutine)(blockSize, whichAllocator->root);
}
/*
@ -368,7 +371,6 @@ void *malloc(size_t blockSize)
return NULL;
}
}
}
/* END REAL MALLOC CODE */