aboutsummaryrefslogtreecommitdiffstats
path: root/awka.c
diff options
context:
space:
mode:
Diffstat (limited to 'awka.c')
-rw-r--r--awka.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/awka.c b/awka.c
new file mode 100644
index 00000000..2de66700
--- /dev/null
+++ b/awka.c
@@ -0,0 +1,44 @@
+/*
+ * some speciallized memory allocation routines
+ *
+ * $Log: awka.c,v $
+ * Revision 1.1 89/03/22 21:04:00 david
+ * Initial revision
+ *
+ */
+
+#include "awk.h"
+
+#define NODECHUNK 50
+
+NODE *nextfree = NULL;
+NODE *lastfree = NULL;
+
+NODE *
+newnode(ty)
+NODETYPE ty;
+{
+ NODE *it;
+ NODE *np;
+
+ if (nextfree == lastfree) {
+ emalloc(nextfree, NODE *, NODECHUNK * sizeof(NODE), "newnode");
+ for (np = nextfree; np < &nextfree[NODECHUNK - 1]; np++)
+ np->nextp = np + 1;
+ np->nextp = lastfree;
+ lastfree = np;
+ }
+ it = nextfree;
+ nextfree = nextfree->nextp;
+ it->type = ty;
+ it->flags = MALLOC;
+ return it;
+}
+
+freenode(it)
+NODE *it;
+{
+ lastfree->nextp = it;
+ it->nextp = NULL;
+ lastfree = it;
+}