2008-08-05 Tom Tromey <tromey@redhat.com>
+ * bcache.c (deprecated_bcache_added): Initialize obstack.
+ (bcache_xmalloc): Don't initialize obstack.
+ (bcache_xfree): Conditionally free obstack.
+ (bcache_memory_used): Update.
+
+2008-08-05 Tom Tromey <tromey@redhat.com>
+
* symfile.c (add_psymbol_to_bcache): Return a const pointer. Use
bcache_full.
(append_psymbol_to_list): Accept a const pointer.
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);
{
/* 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;
}
{
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);
}
int
bcache_memory_used (struct bcache *bcache)
{
+ if (bcache->total_count == 0)
+ return 0;
return obstack_memory_used (&bcache->cache);
}