Main Page | Namespace List | Class List | File List | Class Members | File Members | Related Pages

alloc.c

Go to the documentation of this file.
00001 #include "alloc.h"
00002 #include "error.h"
00003 extern char *malloc();
00004 extern void free();
00005 
00006 #define ALIGNMENT 16 /* XXX: assuming that this alignment is enough */
00007 #define SPACE 4096 /* must be multiple of ALIGNMENT */
00008 
00009 typedef union { char irrelevant[ALIGNMENT]; double d; } aligned;
00010 static aligned realspace[SPACE / ALIGNMENT];
00011 #define space ((char *) realspace)
00012 static unsigned int avail = SPACE; /* multiple of ALIGNMENT; 0<=avail<=SPACE */
00013 
00014 /*@null@*//*@out@*/char *alloc(n)
00015 unsigned int n;
00016 {
00017   char *x;
00018   n = ALIGNMENT + n - (n & (ALIGNMENT - 1)); /* XXX: could overflow */
00019   if (n <= avail) { avail -= n; return space + avail; }
00020   x = malloc(n);
00021   if (!x) errno = error_nomem;
00022   return x;
00023 }
00024 
00025 void alloc_free(x)
00026 char *x;
00027 {
00028   if (x >= space)
00029     if (x < space + SPACE)
00030       return; /* XXX: assuming that pointers are flat */
00031   free(x);
00032 }

Generated on Mon Apr 26 09:49:22 2004 for ConstantDataStore by doxygen 1.3.6-20040222