summaryrefslogtreecommitdiff
path: root/src/fortune/memory.c
blob: 807d1b0457442ef4a642ac178469acb80e75b549 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#
#include "defs.h"
#include <stdio.h>

void freeinit(struct Freelist *fl, int size) {
	fl->head = (struct Freenode *)NULL;
	fl->nodesize = size;
}

char *getfree(fl) struct Freelist *fl;
{
	int i;
	struct Freenode *t;
	if (fl->head == (struct Freenode *)NULL) {
		t = (struct Freenode *)myalloc(sqrt_nsites * fl->nodesize);
		alloclist[allocnum] = t;
		allocnum++;
		for (i = 0; i < sqrt_nsites; i += 1)
			makefree((struct Freenode *)((char *)t + i * fl->nodesize), fl);
	};
	t = fl->head;
	fl->head = (fl->head)->nextfree;
	return ((char *)t);
}

void makefree(curr, fl) struct Freenode *curr;struct Freelist *fl;
{
	curr->nextfree = fl->head;
	fl->head = curr;
}

int total_alloc;
char *myalloc(n) unsigned n;
{
	char *t;
	if ((t = malloc(n)) == (char *)0) {
		fprintf(stderr,
						"Insufficient memory processing site %d (%d bytes in use)\n",
						siteidx, total_alloc);
		exit(1);
	};
	total_alloc += n;
	return (t);
}