Re: strdup of param name/nick/blurb
- From: Tim Janik <timj gtk org>
- To: Alex Larsson <alexl redhat com>
- Cc: Gtk+ Developers <gtk-devel-list gnome org>
- Subject: Re: strdup of param name/nick/blurb
- Date: Sun, 1 Jul 2001 05:02:34 +0200 (CEST)
On Sat, 30 Jun 2001, Alex Larsson wrote:
> I made a little patch that prints the amount of memory wasted on
> strdup()ing the name, nick and blurb for paramspecs:
despite API problems with this issue, just two comments on the stats you
collect here:
> Index: gobject/gparam.c
> ===================================================================
> RCS file: /cvs/gnome/glib/gobject/gparam.c,v
> retrieving revision 1.16
> diff -u -p -r1.16 gparam.c
> --- gobject/gparam.c 2001/06/28 17:05:12 1.16
> +++ gobject/gparam.c 2001/07/01 00:58:09
> @@ -242,6 +242,10 @@ g_param_spec_internal (GType para
> GParamFlags flags)
> {
> GParamSpec *pspec;
> + static int name_bloat=0;
> + static int nick_bloat=0;
> + static int blurb_bloat=0;
> +
>
> g_return_val_if_fail (G_TYPE_IS_PARAM (param_type) && param_type !=
> G_TYPE_PARAM, NULL);
> g_return_val_if_fail (name != NULL, NULL);
> @@ -254,6 +258,15 @@ g_param_spec_internal (GType para
> pspec->blurb = g_strdup (blurb);
> pspec->flags = (flags & G_PARAM_USER_MASK) | (flags & G_PARAM_MASK);
>
> + if (pspec->name)
> + name_bloat += strlen (pspec->name) + 1;
this isn't waste, names need to get canonicalized.
> + if (pspec->nick)
> + nick_bloat += strlen (pspec->nick) + 1;
we should probably add extra code here that a) avoids extra dups if
nick==name, b) only counts actually duped nicks.
> + if (pspec->blurb)
> + blurb_bloat += strlen (pspec->blurb) + 1;
> + g_print ("bloat: name=%d nick=%d blurb=%d tot=%d\n",
> + name_bloat, nick_bloat, blurb_bloat,
> + name_bloat + nick_bloat + blurb_bloat);
> return pspec;
> }
>
> / Alex
---
ciaoTJ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]