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

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

ComputeFree(itsSize, emptyHndlOffset)
long itsSize;
int *emptyHndlOffset;

/*
Compute Free looks for a free block ( of at least size itsSize)
between the top of the mpt and the lowest allocated blk of mem. If it
is sucessful, it rets noErr. Addtionally, Compute Free rets an empty
hndl as well as its offset from the base adrs if one exists.

Note:
global variable gTableSizeCountAdrs is defined as a long in order
to do ptr addtion.

calling params:
blk size in bytes
ptr to offset variable

return params:
offset to empty hndl if one exists | zero
err | noErr

Author: Byro
Creation: 01/09/91
Modified: 01/22/91
Revision:
*/

{
int i;
long delta = ZERO,
*theLowest = (long *) A_HIGH_NUMBER, /* need a high # but, not one confused with -1 */
*thisHndl = NIL;
extern long gMPTsize,
gTableSizeCountAdrs;

*emptyHndlOffset = ZERO;

/* look for lowest non-NIL adrs in mpt */

for (i = 1; i <= gMPTsize; i++)
{
thisHndl = (long *) (gTableSizeCountAdrs + (i * BYTE_OFFSET));

if (((long *) *thisHndl < theLowest) && (*thisHndl != NIL))
theLowest = (long *) *thisHndl; /* set to lowest */

if (*thisHndl == NIL) /* locate empty ele */
*emptyHndlOffset = i;
}

/* compute free space delta */

if (theLowest != (long *) A_HIGH_NUMBER)
delta = (long) (--theLowest) - (gTableSizeCountAdrs + ((gMPTsize + 1) * BYTE_OFFSET));
else
delta = itsSize + 1; /* case for all nil mpt */

/* cmp free space with allocated space */

if (delta < itsSize)
return(!NO_ERR); /* oh no err! */

return(NO_ERR); /* victorious! */
}



  3 Responses to “Category : C Source Code
Archive   : HEAPMAN.ZIP
Filename : COMPUTEF.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: http://www.os2museum.com/wp/mtswslnk/