Commit f7cdb246 authored by Radim Kolář's avatar Radim Kolář

Removed support for MYMALLOC

parent 53302ac6
......@@ -14,16 +14,8 @@ static char *c_sccsid = "@(#)config.h 9.5 91/06/11";
#define STDIO_H <stdio.h>
#define CTYPE_H <ctype.h>
#ifdef MYMALLOC
#define malloc mymalloc
#define calloc(n, s) malloc ((n)*(s))
#define free(s)
#define cfree(s)
extern char *memget();
#else /* !MYMALLOC */
#include <stdlib.h>
#include <string.h>
#endif /* MYMALLOC */
#ifdef STRCHR
#define index strchr
......
......@@ -103,13 +103,7 @@ freetable(t, size)
node **t;
long size;
{
#ifdef MYMALLOC
STATIC void addtoheap();
addtoheap((char *) t, size * sizeof(node *));
#else
free((char *) t);
#endif
}
STATIC void
......@@ -154,118 +148,3 @@ wasted()
return;
vprintf(stderr, "memory allocator wasted %ld bytes\n", Memwaste);
}
#ifdef MYMALLOC
/* use c library malloc/calloc here, and here only */
#undef malloc
#undef calloc
/* imports */
extern char *malloc(), *calloc();
/* private */
STATIC int align();
/* allocate in MBUFSIZ chunks. 4k works ok (less 16 for malloc quirks). */
#define MBUFSIZ (4 * 1024 - 16)
/*
* mess with ALIGN at your peril. longword (== 0 mod 4)
* alignment seems to work everywhere.
*/
#define ALIGN 2
typedef struct heap heap;
struct heap {
heap *h_next;
long h_size;
};
static heap *Mheap; /* not to be confused with a priority queue */
STATIC void
addtoheap(p, size)
char *p;
long size;
{ int adjustment;
heap *pheap;
/* p is aligned, but it doesn't hurt to check */
adjustment = align(p);
p += adjustment;
size -= adjustment;
if (size < 1024)
return; /* can't happen */
pheap = (heap *) p; /* pheap is shorthand */
pheap->h_next = Mheap;
pheap->h_size = size;
Mheap = pheap;
}
/*
* buffered malloc()
* returns space initialized to 0. calloc isn't used, since
* strclear can be faster.
*
* free is ignored, except for very large objects,
* which are returned to the heap with addtoheap().
*/
char *
mymalloc(n)
register unsigned int n;
{ static unsigned int size; /* how much do we have on hand? */
static char *mstash; /* where is it? */
register char *rval;
if (n >= 1024) { /* for hash table */
rval = malloc(n); /* aligned */
if (rval)
strclear(rval, n);
return rval;
}
n += align((char *) n); /* keep everything aligned */
if (n > size) {
Memwaste += size; /* toss the fragment */
/* look in the heap */
if (Mheap) {
mstash = (char *) Mheap; /* aligned */
size = Mheap->h_size;
Mheap = Mheap->h_next;
} else {
mstash = malloc(MBUFSIZ); /* aligned */
if (mstash == 0) {
size = 0;
return 0;
}
size = MBUFSIZ;
}
strclear(mstash, size); /* what if size > 2^16? */
}
rval = mstash;
mstash += n;
size -= n;
return rval;
}
/*
* what's the (mis-)alignment of n? return the complement of
* n mod 2^ALIGN
*/
STATIC int
align(n)
char *n;
{ register int abits; /* misalignment bits in n */
abits = (int) n & ~(0xff << ALIGN) & 0xff;
if (abits == 0)
return 0;
return (1 << ALIGN) - abits;
}
#endif /*MYMALLOC*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment