diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2009-07-28 00:21:12 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2009-07-28 00:21:12 +0000 |
commit | 3e5284a0da373cc2e83a934af14c90f46cc4f547 (patch) | |
tree | 2a4006dd86e586cf45438caf010ec9babf9b98bb /src | |
parent | d398997c9328e1a32bb37084f8c45fee6a2557ee (diff) | |
download | libwapcaplet-3e5284a0da373cc2e83a934af14c90f46cc4f547.tar.gz libwapcaplet-3e5284a0da373cc2e83a934af14c90f46cc4f547.tar.bz2 |
Keep a record of the amount of memory consumed by a lwc_context.
svn path=/trunk/libwapcaplet/; revision=8834
Diffstat (limited to 'src')
-rw-r--r-- | src/libwapcaplet.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/libwapcaplet.c b/src/libwapcaplet.c index 87704bd..4996c6f 100644 --- a/src/libwapcaplet.c +++ b/src/libwapcaplet.c @@ -53,6 +53,7 @@ struct lwc_context_s { lwc_string * buckets[NR_BUCKETS]; lwc_refcounter refcnt; bool refweak; + size_t size; }; lwc_error @@ -72,6 +73,7 @@ lwc_create_context(lwc_allocator_fn alloc, void *pw, (*ret)->alloc_pw = pw; (*ret)->refcnt = 1; (*ret)->refweak = true; + (*ret)->size = sizeof(lwc_context); return lwc_error_ok; } @@ -130,6 +132,7 @@ __lwc_context_intern(lwc_context *ctx, lwc_hash h; lwc_hash bucket; lwc_string *str; + size_t required_size; assert(ctx); assert((s != NULL) || (slen == 0)); @@ -151,7 +154,9 @@ __lwc_context_intern(lwc_context *ctx, } /* Add one for the additional NUL. */ - *ret = str = LWC_ALLOC(sizeof(lwc_string) + slen + 1); + required_size = sizeof(lwc_string) + slen + 1; + + *ret = str = LWC_ALLOC(required_size); if (str == NULL) return lwc_error_oom; @@ -161,7 +166,10 @@ __lwc_context_intern(lwc_context *ctx, if (str->next != NULL) str->next->prevptr = &(str->next); ctx->buckets[bucket] = str; - + + /* Keep context size in sync */ + ctx->size += required_size; + str->len = slen; str->hash = h; str->refcnt = 1; @@ -235,7 +243,10 @@ lwc_context_string_unref(lwc_context *ctx, lwc_string *str) if (str->insensitive != NULL && str->refcnt == 0) lwc_context_string_unref(ctx, str->insensitive); - + + /* Reduce context size by appropriate amount (+1 for trailing NUL) */ + ctx->size -= sizeof(lwc_string) + str->len + 1; + #ifndef NDEBUG memset(str, 0xA5, sizeof(*str) + str->len); #endif @@ -353,3 +364,12 @@ lwc_string_hash_value(lwc_string *str) return str->hash; } + +size_t +lwc_context_size(lwc_context *ctx) +{ + assert(ctx); + + return ctx->size; +} + |