summaryrefslogtreecommitdiff
path: root/gdb/bcache.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2008-08-05 20:43:16 +0000
committerTom Tromey <tromey@redhat.com>2008-08-05 20:43:16 +0000
commit9e2a9a51639287046914b2afc7d99a95c4d97f35 (patch)
tree033efa2c095cd07f5473268d89d1a1ec8bf24088 /gdb/bcache.c
parentda3f7c65d4eec103b10f09031d06691b2d40e4a9 (diff)
downloadgdb-9e2a9a51639287046914b2afc7d99a95c4d97f35.tar.gz
* bcache.c (deprecated_bcache_added): Initialize obstack.
(bcache_xmalloc): Don't initialize obstack. (bcache_xfree): Conditionally free obstack. (bcache_memory_used): Update.
Diffstat (limited to 'gdb/bcache.c')
-rw-r--r--gdb/bcache.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/gdb/bcache.c b/gdb/bcache.c
index 589de6a252c..f96993ba529 100644
--- a/gdb/bcache.c
+++ b/gdb/bcache.c
@@ -217,6 +217,16 @@ bcache_full (const void *addr, int length, struct bcache *bcache, int *added)
if (added)
*added = 0;
+ /* Lazily initialize the obstack. This can save quite a bit of
+ memory in some cases. */
+ if (bcache->total_count == 0)
+ {
+ /* We could use obstack_specify_allocation here instead, but
+ gdb_obstack.h specifies the allocation/deallocation
+ functions. */
+ obstack_init (&bcache->cache);
+ }
+
/* If our average chain length is too high, expand the hash table. */
if (bcache->unique_count >= bcache->num_buckets * CHAIN_LENGTH_THRESHOLD)
expand_hash_table (bcache);
@@ -271,10 +281,6 @@ bcache_xmalloc (void)
{
/* Allocate the bcache pre-zeroed. */
struct bcache *b = XCALLOC (1, struct bcache);
- /* We could use obstack_specify_allocation here instead, but
- gdb_obstack.h specifies the allocation/deallocation
- functions. */
- obstack_init (&b->cache);
return b;
}
@@ -284,7 +290,9 @@ bcache_xfree (struct bcache *bcache)
{
if (bcache == NULL)
return;
- obstack_free (&bcache->cache, 0);
+ /* Only free the obstack if we actually initialized it. */
+ if (bcache->total_count > 0)
+ obstack_free (&bcache->cache, 0);
xfree (bcache->bucket);
xfree (bcache);
}
@@ -443,5 +451,7 @@ print_bcache_statistics (struct bcache *c, char *type)
int
bcache_memory_used (struct bcache *bcache)
{
+ if (bcache->total_count == 0)
+ return 0;
return obstack_memory_used (&bcache->cache);
}