home *** CD-ROM | disk | FTP | other *** search
- /*
- * memory.c
- *
- * Practical Algorithms for Image Analysis
- *
- * Copyright (c) 1997, 1998, 1999 MLMSoftwareGroup, LLC
- */
-
- /*
- * MEMORY.C
- *
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include "vor.h"
-
-
- void
- freeinit (fl, size)
- 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);
- 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);
- }
-