ftp.nice.ch/pub/next/unix/audio/fugue.s.tar.gz#/fugue/mmalloc.c

This is mmalloc.c in view mode; [Download] [Up]

/*
 * FILE: mmalloc.c
 *   BY: Christopher Lee Fraley (cf0v@spice.cs.cmu.edu)
 * DESC: Debugging malloc() & free()
 *
 * 1.0 (27-APR-89) - created. (cf0v)
 */

#include <stdio.h>
char *malloc();

#define TRUE	1
#define FALSE	0
#define MAX	1000

typedef struct _stuff
   {
   char *ptr;
   char used;
   } PtrType, *PtrPtr;

PtrType Ptrs[MAX];
int Initd = FALSE;


char *mmalloc(size)
unsigned int size;
{
   char *temp;
   int i;

   if (!Initd)
      for (Initd=TRUE, i=0; i<MAX; i++)
	 Ptrs[i].used = FALSE;
   temp = malloc(size);
   fprintf(stderr, "mmalloc(): temp=%x\t", temp);
   for (i=0; i<MAX; i++)
      {
      if (!Ptrs[i].used)
	 {
	 Ptrs[i].ptr = temp;
	 fprintf(stderr, "Ptrs[%d].ptr=%x\n", i, Ptrs[i].ptr);
	 Ptrs[i].used = TRUE;
	 return (temp);
	 }
      }
   fprintf(stderr, "Could not save mmalloc pointer:%x", temp);
   return (temp);
}



void mfree(ptr)
char *ptr;
{
   int i;

   for (i=0; i<MAX; i++)
      {
      if (Ptrs[i].ptr == ptr)
	 {
	 fprintf(stderr, "mfree(): ptr=%x\n", ptr);
	 free(ptr);
	 Ptrs[i].used = FALSE;
	 return;
	 }
      }
   fprintf (stderr, "Illegal mfree(%x)\n", ptr);
   for (i=0; i<MAX; i++);  /* delay */
   i = *(int *)0x0;        /* create Segmentation Fault */
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.