1 /* $Id: alloc.c,v 1.6 1994/06/24 10:29:20 ceriel Exp $ */
3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
24 STATIC unsigned maxuse, curruse;
29 if ((curruse += (unsigned) (size+2)) > maxuse) maxuse = curruse;
43 fprintf(stderr,"Maximal core usage (excl. buffers):%u\n",maxuse);
50 * The following two sizetables contain the sizes of the various kinds
51 * of line and argument structures.
52 * The assumption when making the tables was that every non-byte object
53 * had to be aligned on an even boundary. On machines where alignment
54 * is worse ( for example a long has to be aligned on a longword bound )
55 * these tables should be revised.
56 * A wasteful but safe approach is to replace every line of them by
65 2*sizeof(line_p)+2*sizeof(byte),
66 2*sizeof(line_p)+2*sizeof(byte)+sizeof(short),
67 2*sizeof(line_p)+2*sizeof(byte)+sizeof(offset),
68 2*sizeof(line_p)+2*sizeof(byte)+sizeof(lab_id),
69 2*sizeof(line_p)+2*sizeof(byte)+sizeof(obj_p),
70 2*sizeof(line_p)+2*sizeof(byte)+sizeof(proc_p),
71 2*sizeof(line_p)+2*sizeof(byte)+sizeof(arg_p),
75 sizeof(arg_p)+sizeof(short)+sizeof(offset),
76 sizeof(arg_p)+sizeof(short)+sizeof(lab_id),
77 sizeof(arg_p)+sizeof(short)+sizeof(obj_p),
78 sizeof(arg_p)+sizeof(short)+sizeof(proc_p),
79 sizeof(arg_p)+sizeof(short)+sizeof(argb_t),
80 sizeof(arg_p)+sizeof(short)+sizeof(short)+sizeof(argb_t),
81 sizeof(arg_p)+sizeof(short)+sizeof(short)+sizeof(argb_t),
82 sizeof(arg_p)+sizeof(short)+sizeof(short)+sizeof(argb_t)
110 * 1) typed alloc and free routines
111 * 2) untyped raw core allocation
118 line_p newline(optyp) int optyp; {
122 lnp = (line_p) newcore(lsizetab[kind]);
127 oldline(lnp) register line_p lnp; {
128 register kind=TYPE(lnp)&BMASK;
132 oldcore((char *) lnp,lsizetab[kind]);
135 arg_p newarg(kind) int kind; {
138 ap = (arg_p) newcore(asizetab[kind]);
143 oldargs(ap) register arg_p ap; {
146 while (ap != (arg_p) 0) {
150 oldargb(ap->a_a.a_string.ab_next);
155 oldargb(ap->a_a.a_con.ac_con.ab_next);
158 oldcore((char *) ap,asizetab[ap->a_type]);
163 oldargb(abp) register argb_p abp; {
164 register argb_p next;
166 while (abp != (argb_p) 0) {
168 oldcore((char *) abp,sizeof (argb_t));
173 oldobjects(op) register obj_p op; {
176 while (op != (obj_p) 0) {
178 oldcore((char *) op, sizeof(struct obj));
183 olddblock(dbl) dblock_p dbl; {
184 oldobjects(dbl->d_objlist);
185 oldargs(dbl->d_values);
186 oldcore((char *) dbl, sizeof(struct dblock));
190 short **newmap(length) short length; {
191 return((short **) newcore((length+1) * sizeof(short *)));
195 oldmap(mp,length) short **mp, length; {
196 oldcore((char *) mp, (length+1) * sizeof(short *));
200 cset newbitvect(n) short n; {
201 return((cset) newcore((n-1)*sizeof(int) + sizeof(struct bitvector)));
202 /* sizeof(struct bitvector) equals to the size of a struct with
203 * one short, followed by one ALLIGNED int. So the above statement
204 * also works e.g. on a VAX.
209 oldbitvect(s,n) cset s; short n; {
210 oldcore((char *) s, (n-1)*sizeof(int) + sizeof(struct bitvector));
214 short *newtable(length) short length; {
215 return((short *) newcore((length+1) * sizeof(short)));
219 oldtable(mp,length) short **mp, length; {
220 oldcore((char *) mp, (length+1) * sizeof(short));
223 cond_p newcondtab(l) int l;
225 return (cond_p) newcore(l * (sizeof (struct cond_tab)));
228 oldcondtab(tab) cond_p tab;
231 for (i = 0; tab[i].mc_cond != DEFAULT; i++);
232 oldcore((char *) tab,((i+1) * sizeof (struct cond_tab)));
236 char *myalloc(size) register size; {
239 p = calloc((unsigned) size, 1);
241 error("out of memory");