From 6e9a647e94749f0b9301f2cbf9a4239a7078806c Mon Sep 17 00:00:00 2001 From: Ted Lemon Date: Wed, 5 Mar 1997 06:34:27 +0000 Subject: [PATCH] Maintain a free list for tree_cache structs --- common/alloc.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/common/alloc.c b/common/alloc.c index dcf4672d6..7799fc377 100644 --- a/common/alloc.c +++ b/common/alloc.c @@ -42,7 +42,7 @@ #ifndef lint static char copyright[] = -"$Id: alloc.c,v 1.9 1996/08/28 01:19:42 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; +"$Id: alloc.c,v 1.10 1997/03/05 06:34:27 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -96,10 +96,22 @@ struct tree *new_tree (name) return rval; } +struct tree_cache *free_tree_caches; + struct tree_cache *new_tree_cache (name) char *name; { - struct tree_cache *rval = dmalloc (sizeof (struct tree_cache), name); + struct tree_cache *rval; + + if (free_tree_caches) { + rval = free_tree_caches; + free_tree_caches = + (struct tree_cache *)(rval -> value); + } else { + rval = dmalloc (sizeof (struct tree_cache), name); + if (!rval) + error ("unable to allocate tree cache for %s.", name); + } return rval; } @@ -222,7 +234,8 @@ void free_tree_cache (ptr, name) struct tree_cache *ptr; char *name; { - dfree ((VOIDPTR)ptr, name); + ptr -> value = (unsigned char *)free_tree_caches; + free_tree_caches = ptr; } void free_packet (ptr, name) -- 2.47.2