diff options
author | Robert James Kaes <rjkaes@users.sourceforge.net> | 2001-09-08 18:58:02 +0000 |
---|---|---|
committer | Robert James Kaes <rjkaes@users.sourceforge.net> | 2001-09-08 18:58:02 +0000 |
commit | d5253ec5f435b26c50ca4cb649d3f47b800cbbd8 (patch) | |
tree | 2f039790578dc717d9374a51c2797dae31466e11 /src | |
parent | 78bc90cd07a2718b08493e8483fed93b749f7263 (diff) | |
download | tinyproxy-d5253ec5f435b26c50ca4cb649d3f47b800cbbd8.tar.gz tinyproxy-d5253ec5f435b26c50ca4cb649d3f47b800cbbd8.zip |
Lowered the number BUFARRAY and BUFSIZE constants to reduce the maximum
memory usage of a ternary tree. It now should not exceed 4MB of memory.
Diffstat (limited to '')
-rw-r--r-- | src/ternary.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/ternary.c b/src/ternary.c index a118425..dfc423a 100644 --- a/src/ternary.c +++ b/src/ternary.c @@ -1,4 +1,4 @@ -/* $Id: ternary.c,v 1.9 2001-09-07 00:38:03 rjkaes Exp $ +/* $Id: ternary.c,v 1.10 2001-09-08 18:58:02 rjkaes Exp $ * * This module creates a Ternary Search Tree which can store both string * keys, and arbitrary data for each key. It works similar to a hash, and @@ -37,6 +37,7 @@ #include "log.h" #include "ternary.h" #include "tinyproxy.h" +#include "utils.h" /* * Macros for the tree structures (limits) @@ -54,8 +55,8 @@ typedef struct tnode { /* * The structure for each root of a ternary tree. */ -#define BUFSIZE 1024 -#define BUFARRAY 1024 +#define BUFSIZE 512 +#define BUFARRAY 512 typedef struct ttree { TERNARY token; /* contains unique ternary tree ID */ Tnode *tree_root; @@ -217,7 +218,7 @@ TERNARY ternary_new(void) /* * Allocate a new tree */ - if ((trees[cur] = malloc(sizeof(Ttree))) == NULL) { + if ((trees[cur] = safemalloc(sizeof(Ttree))) == NULL) { ERRBUF("ternary_new: malloc: no more memory"); return TE_NOROOM; } @@ -336,7 +337,7 @@ int ternary_insert_replace(TERNARY tno, const char *s, void *data, for (;;) { if (tree->bufn-- == 0) { - tree->buf = calloc(BUFSIZE, sizeof(Tnode)); + tree->buf = safecalloc(BUFSIZE, sizeof(Tnode)); if (!tree->buf) { ERRBUF("ternary_insert: malloc: no more memory"); return TE_NOROOM; |