Category : C Source Code
Archive   : HEAPMAN.ZIP
Filename : MMMAIN.C
Output of file : MMMAIN.C contained in archive : HEAPMAN.ZIP
#include
#include "mm.h"
/******************************* globals ****************************/
typedef struct node
{
int aNum;
struct node *next;
} node;
main()
/*
This is the main routine for appl heap memory manager. It is used
to exercise the mm functions. In a real applications, the mm functions
are called from the application. This example creates a linked list
and prints it to console.
*/
{
dataStruct *ablk;
int i,
n = ZERO;
long theSize = 1024,
mptSize = 4,
*nextTmp,
*NuHndl(),
*theHead,
*tmp;
node *p,
*q;
void DeInitHeap();
printf("Input size of list in decimal: \t");
scanf("%d", &n);
p = (node *) NIL;
/* initialize heap */
if (InitHeap(theSize, mptSize) < ZERO)
{
printf("Problems initializing heap \n");
exit(MINUS_ONE);
}
/* create list starting with the last element */
for (i = n; i > ZERO; i--)
{
q = p;
if ((tmp = NuHndl(sizeof(node) + HDR)) == NIL)
{
if (tmpMoreMasters(1) == NO_ERR) /* try to expand mpt if full */
{
if ((tmp = NuHndl(sizeof(node) + HDR)) == NIL)
{
printf("Unable to allocate space for extra node\n");
exit(MINUS_ONE);
}
}
else
{
printf("Unable to allocate space for node\n");
exit(MINUS_ONE);
}
}
if (i == n)
theHead = tmp; /* head of list */
ablk = (dataStruct *) *tmp;
p = (node *) ablk->dataSpace;
/* p = (node *) malloc(sizeof(node)); */
p->aNum = i * 3;
p->next = q;
}
tmp = theHead; /* link to head of list */
/* xverse list displaying each ele's value */
while (p != NIL)
{
printf("%d \n", p->aNum);
p = p->next;
}
while (tmp != NIL) /* release mem */
{
nextTmp = tmp; /* xverse mpt releasing hndls */
nextTmp++;
nextTmp = (long *) *nextTmp;
if (DisposeHndl(tmp) != NO_ERR)
printf("hey dude! unable to dispose of hndl!\n");
tmp = nextTmp;
}
/* make another list */
for (i = 2; i > ZERO; i--)
{
q = p;
if ((tmp = NuHndl(sizeof(node) + HDR)) == NIL)
{
printf("Unable to allocate space for list\n");
exit(MINUS_ONE);
}
ablk = (dataStruct *) *tmp;
p = (node *) ablk->dataSpace;
p->aNum = i * 5;
p->next = q;
}
/* print it! */
while (p != NIL)
{
printf("%d \n", p->aNum);
p = p->next;
}
DeInitHeap(); /* release space */
exit(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/