1 |
/* Copyright (c) 1990 Regents of the University of California */ |
2 |
|
3 |
#ifndef lint |
4 |
static char SCCSid[] = "$SunId$ LBL"; |
5 |
#endif |
6 |
|
7 |
/* |
8 |
* Basic memory allocation w/o overhead. |
9 |
* Calls malloc(3) for big requests. |
10 |
* |
11 |
*/ |
12 |
|
13 |
#define NULL 0 |
14 |
|
15 |
#ifndef MBLKSIZ |
16 |
#define MBLKSIZ 16376 /* size of memory allocation block */ |
17 |
#endif |
18 |
#define WASTEFRAC 4 /* don't waste more than this */ |
19 |
#ifndef ALIGN |
20 |
#define ALIGN int /* type for alignment */ |
21 |
#endif |
22 |
#define BYTES_WORD sizeof(ALIGN) |
23 |
|
24 |
|
25 |
char * |
26 |
bmalloc(n) /* allocate a block of n bytes, no refunds */ |
27 |
register unsigned n; |
28 |
{ |
29 |
extern char *malloc(); |
30 |
static char *bpos = NULL; |
31 |
static unsigned nrem = 0; |
32 |
|
33 |
if (n > nrem && (n > MBLKSIZ || nrem > MBLKSIZ/WASTEFRAC)) |
34 |
return(malloc(n)); /* too big */ |
35 |
|
36 |
n = (n+(BYTES_WORD-1))&~(BYTES_WORD-1); /* word align */ |
37 |
|
38 |
if (n > nrem) { |
39 |
if ((bpos = malloc((unsigned)MBLKSIZ)) == NULL) { |
40 |
nrem = 0; |
41 |
return(NULL); |
42 |
} |
43 |
nrem = MBLKSIZ; |
44 |
} |
45 |
bpos += n; |
46 |
nrem -= n; |
47 |
return(bpos - n); |
48 |
} |
49 |
|
50 |
|
51 |
bfree(p, n) /* free random memory */ |
52 |
char *p; |
53 |
unsigned n; |
54 |
{ |
55 |
/* not implemented */ |
56 |
} |