Category : C Source Code
Archive   : HEAPMAN.ZIP
Filename : COMPACTH.C
CompactHeap()
/*
This function defragments the heap. It accomplishes this by first
sorting the mpt addresses highest to lowest. Next, it checks allocated
blocks looking for gaps between them. If any gaps are found, it then
moves one or more blocks to close the gap.
calling params:
none
return params:
err | noErr
Author: Byro
Created: 01/11/91
Modified: 01/24/91 (debug phase)
Revision: (enhancement, bug fix info; date, who, nature of change)
*/
{
long *baseAdrs = NIL,
*lastHighest = NIL,
*nuAdrs = NIL;
void SortMPT();
dataStruct *tmpPtr = NIL;
extern long *gTableSizeCountAdrs,
*gTopOfHeap;
lastHighest = gTopOfHeap;
SortMPT();
/* pt to highest blk of mem */
baseAdrs = gTableSizeCountAdrs;
baseAdrs++;
nuAdrs = (long *) *baseAdrs;
/* parse through mpt looking for gaps */
while (nuAdrs != NIL)
{
tmpPtr = (dataStruct *) *nuAdrs; /* look at data blk */
/* check for gap */
if (lastHighest != (long *) (tmpPtr->blkSize + tmpPtr))
{
/* gap detected! */
if (MoveHigh(&nuAdrs, lastHighest) != NO_ERR)
return(COMPACT_HEAP);
if (UpdateBlk(nuAdrs, MINUS_ONE) != NO_ERR)
return(COMPACT_HEAP);
}
lastHighest = (long *) *nuAdrs; /* look for next gap */
nuAdrs++;
nuAdrs = (long *) *nuAdrs; /* pt to next lowest adrs */
}
return(NO_ERR);
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/