[PATCH] Hunk_TempAllocExtend

This patch implements a new memory allocation feature, which allows us
to use the "Temp" hunk as an expandable blob of storage space. The
first user of this will be some "string tree" functions, which build
up an RB tree of strings which will be used for sorting file lists.

We could just use Z_Malloc, but the zone isn't well suited to this
type of allocation (potentially hundreds of small struct + string
allocations) and is probably too small.

diff -urN b/common/zone.c head/common/zone.c
--- b/common/zone.c	2004-08-11 22:35:12.000000000 +0930
+++ head/common/zone.c	2006-01-18 16:48:52.000000000 +1030
@@ -565,6 +565,45 @@
 }
 
 /*
+ * =====================
+ * Hunk_TempAllocExtend
+ *
+ * Extend the existing temp hunk allocation.
+ * Size is the number of extra bytes required
+ * =====================
+ */
+void *
+Hunk_TempAllocExtend(int size)
+{
+    hunk_t *old, *new;
+
+    if (!hunk_tempactive)
+	Sys_Error("%s: temp hunk not active");
+
+    old = (hunk_t *)(hunk_base + hunk_size - hunk_high_used);
+
+    if (old->sentinal != HUNK_SENTINAL)
+	Sys_Error("%s: old sentinal trashed\n", __func__);
+    if (strncmp(old->name, "temp", 8))
+	Sys_Error("%s: old hunk name trashed\n", __func__);
+
+    size = (size + 15) & ~15;
+    if (hunk_size - hunk_low_used - hunk_high_used < size) {
+	Con_Printf("%s: failed on %i bytes\n", __func__, size);
+	return NULL;
+    }
+
+    hunk_high_used += size;
+    Cache_FreeHigh(hunk_high_used);
+
+    new = (hunk_t *)(hunk_base + hunk_size - hunk_high_used);
+    memmove(new, old, sizeof(hunk_t));
+    new->size += size;
+
+    return (void *)(new + 1);
+}
+
+/*
  * ===========================================================================
  *
  * CACHE MEMORY
diff -urN b/include/zone.h head/include/zone.h
--- b/include/zone.h	2004-08-04 21:00:33.000000000 +0930
+++ head/include/zone.h	2006-01-18 16:23:55.000000000 +1030
@@ -107,6 +107,7 @@
 void Hunk_FreeToHighMark(int mark);
 
 void *Hunk_TempAlloc(int size);
+void *Hunk_TempAllocExtend(int size);
 
 void Hunk_Check(void);
 
