/* This software may only be used by you under license from AT&T Corp. ("AT&T"). A copy of AT&T's Source Code Agreement is available at AT&T's Internet website having the URL: If you received this software without first entering into a license with AT&T, you have an infringing copy of this software and cannot use it without violating AT&T's intellectual property rights. */ #pragma prototyped #include "geometry.h" #include "render.h" typedef struct freenode { struct freenode *nextfree; } Freenode; typedef struct freeblock { struct freeblock *next; struct freenode *nodes; } Freeblock; #include "mem.h" #include #include static int gcd (int y, int x) { while (x != y) { if (y < x) x = x - y; else y = y - x; } return x; } #define LCM(x,y) ((x)%(y) == 0 ? (x) : (y)%(x) == 0 ? (y) : x*(y/gcd(x,y))) void freeinit(Freelist *fl, int size) { fl -> head = NULL; fl -> nodesize = LCM(size, sizeof(Freenode)); if (fl->blocklist != NULL) { Freeblock *bp, *np; bp = fl->blocklist; while (bp != NULL) { np = bp->next; free (bp->nodes); free (bp); bp = np; } } fl -> blocklist = NULL; } void * getfree(Freelist *fl) { int i; Freenode *t; Freeblock *mem; if(fl->head == NULL) { int size = fl->nodesize; char *cp; mem = GNEW(Freeblock); mem->nodes = gmalloc (sqrt_nsites * size); cp = (char*)(mem->nodes); for(i=0; inext = fl->blocklist; fl->blocklist = mem; } t = fl -> head; fl -> head = t -> nextfree; return((void *)t); } void makefree(void *curr, Freelist *fl) { ((Freenode*)curr) -> nextfree = fl -> head; fl -> head = (Freenode*)curr; }