Category : C Source Code
Archive   : HEAPMAN.ZIP
Filename : COMPACTH.C

Output of file : COMPACTH.C contained in archive : HEAPMAN.ZIP
#include "mm.h"


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:

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,

lastHighest = gTopOfHeap;

/* pt to highest blk of mem */

baseAdrs = gTableSizeCountAdrs;
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)

if (UpdateBlk(nuAdrs, MINUS_ONE) != NO_ERR)

lastHighest = (long *) *nuAdrs; /* look for next gap */
nuAdrs = (long *) *nuAdrs; /* pt to next lowest adrs */

  3 Responses to “Category : C Source Code
Archive   : HEAPMAN.ZIP
Filename : COMPACTH.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: