added typdef GimpMemsizeFunc.

2007-03-05  Michael Natterer  <mitch@gimp.org>

	* app/core/core-types.h: added typdef GimpMemsizeFunc.

	* app/core/gimp-utils.[ch]: added _foreach() variants of
	GHashTable, GList and GSList functions which take GimpMemsizeFunc
	callbacks. Added gimp_parasite_get_memsize(). Added "data_size"
	parameter to gimp_g_hash_table_get_memsize().

	* app/core/gimp.c
	* app/core/gimppalette.c
	* app/core/gimpparasitelist.c
	* app/pdb/gimppdb.c
	* app/plug-in/gimppluginmanager.c: use the new functions instead
	of itering manually or ignoring the containers' elements. Changed
	callers of gimp_g_hash_table_get_memsize().


svn path=/trunk/; revision=22046
This commit is contained in:
Michael Natterer 2007-03-05 20:09:46 +00:00 committed by Michael Natterer
parent c4c9dbc038
commit 395b06ad8b
9 changed files with 215 additions and 88 deletions

View File

@ -1,3 +1,20 @@
2007-03-05 Michael Natterer <mitch@gimp.org>
* app/core/core-types.h: added typdef GimpMemsizeFunc.
* app/core/gimp-utils.[ch]: added _foreach() variants of
GHashTable, GList and GSList functions which take GimpMemsizeFunc
callbacks. Added gimp_parasite_get_memsize(). Added "data_size"
parameter to gimp_g_hash_table_get_memsize().
* app/core/gimp.c
* app/core/gimppalette.c
* app/core/gimpparasitelist.c
* app/pdb/gimppdb.c
* app/plug-in/gimppluginmanager.c: use the new functions instead
of itering manually or ignoring the containers' elements. Changed
callers of gimp_g_hash_table_get_memsize().
2007-03-05 Sven Neumann <sven@gimp.org>
* plug-ins/common/colorify.c

View File

@ -173,6 +173,9 @@ typedef void (* GimpInitStatusFunc) (const gchar *text1,
typedef gboolean (* GimpObjectFilterFunc) (const GimpObject *object,
gpointer user_data);
typedef gint64 (* GimpMemsizeFunc) (gpointer instance,
gint64 *gui_size);
/* structs */

View File

@ -80,13 +80,54 @@ gimp_g_object_get_memsize (GObject *object)
}
gint64
gimp_g_hash_table_get_memsize (GHashTable *hash)
gimp_g_hash_table_get_memsize (GHashTable *hash,
gint64 data_size)
{
g_return_val_if_fail (hash != NULL, 0);
return (2 * sizeof (gint) +
5 * sizeof (gpointer) +
g_hash_table_size (hash) * 3 * sizeof (gpointer));
g_hash_table_size (hash) * (3 * sizeof (gpointer) + data_size));
}
typedef struct
{
GimpMemsizeFunc func;
gint64 memsize;
gint64 gui_size;
} HashMemsize;
static void
hash_memsize_foreach (gpointer key,
gpointer value,
HashMemsize *memsize)
{
gint64 gui_size = 0;
memsize->memsize += memsize->func (value, &gui_size);
memsize->gui_size += gui_size;
}
gint64
gimp_g_hash_table_get_memsize_foreach (GHashTable *hash,
GimpMemsizeFunc func,
gint64 *gui_size)
{
HashMemsize memsize;
g_return_val_if_fail (hash != NULL, 0);
g_return_val_if_fail (func != NULL, 0);
memsize.func = func;
memsize.memsize = 0;
memsize.gui_size = 0;
g_hash_table_foreach (hash, (GHFunc) hash_memsize_foreach, &memsize);
if (gui_size)
*gui_size = memsize.gui_size;
return memsize.memsize + gimp_g_hash_table_get_memsize (hash, 0);
}
gint64
@ -96,6 +137,22 @@ gimp_g_slist_get_memsize (GSList *slist,
return g_slist_length (slist) * (data_size + sizeof (GSList));
}
gint64
gimp_g_slist_get_memsize_foreach (GSList *slist,
GimpMemsizeFunc func,
gint64 *gui_size)
{
GSList *l;
gint64 memsize = 0;
g_return_val_if_fail (func != NULL, 0);
for (l = slist; l; l = g_slist_next (l))
memsize += sizeof (GSList) + func (l->data, gui_size);
return memsize;
}
gint64
gimp_g_list_get_memsize (GList *list,
gint64 data_size)
@ -103,6 +160,22 @@ gimp_g_list_get_memsize (GList *list,
return g_list_length (list) * (data_size + sizeof (GList));
}
gint64
gimp_g_list_get_memsize_foreach (GList *list,
GimpMemsizeFunc func,
gint64 *gui_size)
{
GList *l;
gint64 memsize = 0;
g_return_val_if_fail (func != NULL, 0);
for (l = list; l; l = g_list_next (l))
memsize += sizeof (GList) + func (l->data, gui_size);
return memsize;
}
gint64
gimp_g_value_get_memsize (GValue *value)
{
@ -210,6 +283,20 @@ gimp_g_param_spec_get_memsize (GParamSpec *pspec)
return memsize + gimp_g_type_instance_get_memsize ((GTypeInstance *) pspec);
}
gint64
gimp_parasite_get_memsize (GimpParasite *parasite,
gint64 *gui_size)
{
gint64 memsize = 0;
if (parasite)
memsize += (sizeof (GimpParasite) +
strlen (parasite->name) + 1 +
parasite->size);
return memsize;
}
/*
* basically copied from gtk_get_default_language()

View File

@ -22,14 +22,27 @@
gint64 gimp_g_type_instance_get_memsize (GTypeInstance *instance);
gint64 gimp_g_object_get_memsize (GObject *object);
gint64 gimp_g_hash_table_get_memsize (GHashTable *hash);
gint64 gimp_g_hash_table_get_memsize (GHashTable *hash,
gint64 data_size);
gint64 gimp_g_hash_table_get_memsize_foreach (GHashTable *hash,
GimpMemsizeFunc func,
gint64 *gui_size);
gint64 gimp_g_slist_get_memsize (GSList *slist,
gint64 data_size);
gint64 gimp_g_slist_get_memsize_foreach (GSList *slist,
GimpMemsizeFunc func,
gint64 *gui_size);
gint64 gimp_g_list_get_memsize (GList *list,
gint64 data_size);
gint64 gimp_g_list_get_memsize_foreach (GList *slist,
GimpMemsizeFunc func,
gint64 *gui_size);
gint64 gimp_g_value_get_memsize (GValue *value);
gint64 gimp_g_param_spec_get_memsize (GParamSpec *pspec);
gint64 gimp_parasite_get_memsize (GimpParasite *parasite,
gint64 *gui_size);
gchar * gimp_get_default_language (const gchar *category);
GimpUnit gimp_get_default_unit (void);

View File

@ -433,8 +433,8 @@ gimp_get_memsize (GimpObject *object,
memsize += gimp_g_object_get_memsize (G_OBJECT (gimp->module_db));
memsize += gimp_g_object_get_memsize (G_OBJECT (gimp->plug_in_manager));
memsize += gimp_g_hash_table_get_memsize (gimp->image_table);
memsize += gimp_g_hash_table_get_memsize (gimp->item_table);
memsize += gimp_g_hash_table_get_memsize (gimp->image_table, 0);
memsize += gimp_g_hash_table_get_memsize (gimp->item_table, 0);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->displays), gui_size);

View File

@ -29,6 +29,7 @@
#include "base/temp-buf.h"
#include "gimp-utils.h"
#include "gimppalette.h"
#include "gimppalette-load.h"
#include "gimppalette-save.h"
@ -66,6 +67,8 @@ static gchar * gimp_palette_get_extension (GimpData *data);
static GimpData * gimp_palette_duplicate (GimpData *data);
static void gimp_palette_entry_free (GimpPaletteEntry *entry);
static gint64 gimp_palette_entry_get_memsize(GimpPaletteEntry *entry,
gint64 *gui_size);
G_DEFINE_TYPE (GimpPalette, gimp_palette, GIMP_TYPE_DATA)
@ -124,18 +127,12 @@ gimp_palette_get_memsize (GimpObject *object,
gint64 *gui_size)
{
GimpPalette *palette = GIMP_PALETTE (object);
GList *list;
gint64 memsize = 0;
for (list = palette->colors; list; list = g_list_next (list))
{
GimpPaletteEntry *entry = list->data;
memsize += sizeof (GList) + sizeof (GimpPaletteEntry);
if (entry->name)
memsize += strlen (entry->name) + 1;
}
memsize += gimp_g_list_get_memsize_foreach (palette->colors,
(GimpMemsizeFunc)
gimp_palette_entry_get_memsize,
gui_size);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
@ -498,3 +495,15 @@ gimp_palette_entry_free (GimpPaletteEntry *entry)
g_free (entry->name);
g_free (entry);
}
static gint64
gimp_palette_entry_get_memsize (GimpPaletteEntry *entry,
gint64 *gui_size)
{
gint64 memsize = sizeof (GimpPaletteEntry);
if (entry->name)
memsize += strlen (entry->name) + 1;
return memsize;
}

View File

@ -149,19 +149,6 @@ gimp_parasite_list_finalize (GObject *object)
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_parasite_list_get_memsize_foreach (gpointer key,
gpointer p,
gpointer m)
{
GimpParasite *parasite = p;
gint64 *memsize = m;
*memsize += (sizeof (GimpParasite) +
strlen (parasite->name) + 1 +
parasite->size);
}
static gint64
gimp_parasite_list_get_memsize (GimpObject *object,
gint64 *gui_size)
@ -170,13 +157,10 @@ gimp_parasite_list_get_memsize (GimpObject *object,
gint64 memsize = 0;
if (list->table)
{
memsize += gimp_g_hash_table_get_memsize (list->table);
g_hash_table_foreach (list->table,
gimp_parasite_list_get_memsize_foreach,
&memsize);
}
memsize += gimp_g_hash_table_get_memsize_foreach (list->table,
(GimpMemsizeFunc)
gimp_parasite_get_memsize,
gui_size);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);

View File

@ -60,9 +60,8 @@ static void gimp_pdb_real_unregister_procedure (GimpPDB *pdb,
static void gimp_pdb_entry_free (gpointer key,
gpointer value,
gpointer user_data);
static void gimp_pdb_entry_memsize (gpointer key,
gpointer value,
gpointer user_data);
static gint64 gimp_pdb_entry_get_memsize (GList *procedures,
gint64 *gui_size);
G_DEFINE_TYPE (GimpPDB, gimp_pdb, GIMP_TYPE_OBJECT)
@ -141,10 +140,11 @@ gimp_pdb_get_memsize (GimpObject *object,
GimpPDB *pdb = GIMP_PDB (object);
gint64 memsize = 0;
memsize += gimp_g_hash_table_get_memsize (pdb->procedures);
memsize += gimp_g_hash_table_get_memsize (pdb->compat_proc_names);
g_hash_table_foreach (pdb->procedures, gimp_pdb_entry_memsize, &memsize);
memsize += gimp_g_hash_table_get_memsize_foreach (pdb->procedures,
(GimpMemsizeFunc)
gimp_pdb_entry_get_memsize,
gui_size);
memsize += gimp_g_hash_table_get_memsize (pdb->compat_proc_names, 0);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
@ -452,17 +452,12 @@ gimp_pdb_entry_free (gpointer key,
}
}
static void
gimp_pdb_entry_memsize (gpointer key,
gpointer value,
gpointer user_data)
static gint64
gimp_pdb_entry_get_memsize (GList *procedures,
gint64 *gui_size)
{
if (value)
{
gint64 *memsize = user_data;
GList *list;
for (list = value; list; list = g_list_next (list))
*memsize += sizeof (GList) + gimp_object_get_memsize (list->data, NULL);
}
return gimp_g_list_get_memsize_foreach (procedures,
(GimpMemsizeFunc)
gimp_object_get_memsize,
gui_size);
}

View File

@ -209,6 +209,13 @@ gimp_plug_in_manager_finalize (GObject *object)
manager->plug_in_procedures = NULL;
}
if (manager->plug_in_defs)
{
g_slist_foreach (manager->plug_in_defs, (GFunc) g_object_unref, NULL);
g_slist_free (manager->plug_in_defs);
manager->plug_in_defs = NULL;
}
if (manager->shm)
{
gimp_plug_in_shm_free (manager->shm);
@ -248,21 +255,33 @@ gimp_plug_in_manager_get_memsize (GimpObject *object,
GimpPlugInManager *manager = GIMP_PLUG_IN_MANAGER (object);
gint64 memsize = 0;
memsize += gimp_g_slist_get_memsize (manager->load_procs, 0 /* FIXME */);
memsize += gimp_g_slist_get_memsize (manager->save_procs, 0 /* FIXME */);
memsize += gimp_g_slist_get_memsize_foreach (manager->plug_in_defs,
(GimpMemsizeFunc)
gimp_object_get_memsize,
gui_size);
memsize += gimp_g_slist_get_memsize (manager->menu_branches,
0 /* FIXME */);
memsize += gimp_g_slist_get_memsize (manager->locale_domains,
0 /* FIXME */);
memsize += gimp_g_slist_get_memsize (manager->help_domains,
0 /* FIXME */);
memsize += gimp_g_slist_get_memsize (manager->plug_in_procedures, 0);
memsize += gimp_g_slist_get_memsize (manager->load_procs, 0);
memsize += gimp_g_slist_get_memsize (manager->save_procs, 0);
memsize += gimp_g_slist_get_memsize (manager->menu_branches, 0 /* FIXME */);
memsize += gimp_g_slist_get_memsize (manager->locale_domains, 0 /* FIXME */);
memsize += gimp_g_slist_get_memsize (manager->help_domains, 0 /* FIXME */);
memsize += gimp_g_slist_get_memsize_foreach (manager->open_plug_ins,
(GimpMemsizeFunc)
gimp_object_get_memsize,
gui_size);
memsize += gimp_g_slist_get_memsize (manager->plug_in_stack, 0 /* FIXME */);
memsize += gimp_g_slist_get_memsize (manager->history, 0);
memsize += 0; /* FIXME manager->shm */
memsize += gimp_object_get_memsize (GIMP_OBJECT (manager->interpreter_db),
gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (manager->environ_table),
gui_size);
memsize += gimp_g_list_get_memsize (manager->data_list,
0 /* FIXME */);
memsize += 0; /* FIXME manager->plug_in_debug */
memsize += gimp_g_list_get_memsize (manager->data_list, 0 /* FIXME */);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);