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> 2007-03-05 Sven Neumann <sven@gimp.org>
* plug-ins/common/colorify.c * plug-ins/common/colorify.c

View File

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

View File

@ -80,13 +80,54 @@ gimp_g_object_get_memsize (GObject *object)
} }
gint64 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); g_return_val_if_fail (hash != NULL, 0);
return (2 * sizeof (gint) + return (2 * sizeof (gint) +
5 * sizeof (gpointer) + 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 gint64
@ -96,6 +137,22 @@ gimp_g_slist_get_memsize (GSList *slist,
return g_slist_length (slist) * (data_size + sizeof (GSList)); 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 gint64
gimp_g_list_get_memsize (GList *list, gimp_g_list_get_memsize (GList *list,
gint64 data_size) gint64 data_size)
@ -103,6 +160,22 @@ gimp_g_list_get_memsize (GList *list,
return g_list_length (list) * (data_size + sizeof (GList)); 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 gint64
gimp_g_value_get_memsize (GValue *value) 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); 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() * basically copied from gtk_get_default_language()

View File

@ -20,35 +20,48 @@
#define __APP_GIMP_UTILS_H__ #define __APP_GIMP_UTILS_H__
gint64 gimp_g_type_instance_get_memsize (GTypeInstance *instance); gint64 gimp_g_type_instance_get_memsize (GTypeInstance *instance);
gint64 gimp_g_object_get_memsize (GObject *object); 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 gimp_g_slist_get_memsize (GSList *slist, gint64 data_size);
gint64 data_size); gint64 gimp_g_hash_table_get_memsize_foreach (GHashTable *hash,
gint64 gimp_g_list_get_memsize (GList *list, GimpMemsizeFunc func,
gint64 data_size); gint64 *gui_size);
gint64 gimp_g_value_get_memsize (GValue *value); gint64 gimp_g_slist_get_memsize (GSList *slist,
gint64 gimp_g_param_spec_get_memsize (GParamSpec *pspec); 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);
gchar * gimp_get_default_language (const gchar *category); gint64 gimp_parasite_get_memsize (GimpParasite *parasite,
GimpUnit gimp_get_default_unit (void); gint64 *gui_size);
GParameter * gimp_parameters_append (GType object_type, gchar * gimp_get_default_language (const gchar *category);
GParameter *params, GimpUnit gimp_get_default_unit (void);
gint *n_params,
...) G_GNUC_NULL_TERMINATED;
GParameter * gimp_parameters_append_valist (GType object_type,
GParameter *params,
gint *n_params,
va_list args);
void gimp_parameters_free (GParameter *params,
gint n_params);
void gimp_value_array_truncate (GValueArray *args, GParameter * gimp_parameters_append (GType object_type,
gint n_values); GParameter *params,
gint *n_params,
...) G_GNUC_NULL_TERMINATED;
GParameter * gimp_parameters_append_valist (GType object_type,
GParameter *params,
gint *n_params,
va_list args);
void gimp_parameters_free (GParameter *params,
gint n_params);
gchar * gimp_get_temp_filename (Gimp *gimp, void gimp_value_array_truncate (GValueArray *args,
const gchar *extension); gint n_values);
gchar * gimp_get_temp_filename (Gimp *gimp,
const gchar *extension);
#endif /* __APP_GIMP_UTILS_H__ */ #endif /* __APP_GIMP_UTILS_H__ */

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->module_db));
memsize += gimp_g_object_get_memsize (G_OBJECT (gimp->plug_in_manager)); 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->image_table, 0);
memsize += gimp_g_hash_table_get_memsize (gimp->item_table); memsize += gimp_g_hash_table_get_memsize (gimp->item_table, 0);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->displays), gui_size); memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->displays), gui_size);

View File

@ -29,6 +29,7 @@
#include "base/temp-buf.h" #include "base/temp-buf.h"
#include "gimp-utils.h"
#include "gimppalette.h" #include "gimppalette.h"
#include "gimppalette-load.h" #include "gimppalette-load.h"
#include "gimppalette-save.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 GimpData * gimp_palette_duplicate (GimpData *data);
static void gimp_palette_entry_free (GimpPaletteEntry *entry); 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) G_DEFINE_TYPE (GimpPalette, gimp_palette, GIMP_TYPE_DATA)
@ -124,18 +127,12 @@ gimp_palette_get_memsize (GimpObject *object,
gint64 *gui_size) gint64 *gui_size)
{ {
GimpPalette *palette = GIMP_PALETTE (object); GimpPalette *palette = GIMP_PALETTE (object);
GList *list;
gint64 memsize = 0; gint64 memsize = 0;
for (list = palette->colors; list; list = g_list_next (list)) memsize += gimp_g_list_get_memsize_foreach (palette->colors,
{ (GimpMemsizeFunc)
GimpPaletteEntry *entry = list->data; gimp_palette_entry_get_memsize,
gui_size);
memsize += sizeof (GList) + sizeof (GimpPaletteEntry);
if (entry->name)
memsize += strlen (entry->name) + 1;
}
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object, return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size); gui_size);
@ -498,3 +495,15 @@ gimp_palette_entry_free (GimpPaletteEntry *entry)
g_free (entry->name); g_free (entry->name);
g_free (entry); 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); 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 static gint64
gimp_parasite_list_get_memsize (GimpObject *object, gimp_parasite_list_get_memsize (GimpObject *object,
gint64 *gui_size) gint64 *gui_size)
@ -170,13 +157,10 @@ gimp_parasite_list_get_memsize (GimpObject *object,
gint64 memsize = 0; gint64 memsize = 0;
if (list->table) if (list->table)
{ memsize += gimp_g_hash_table_get_memsize_foreach (list->table,
memsize += gimp_g_hash_table_get_memsize (list->table); (GimpMemsizeFunc)
gimp_parasite_get_memsize,
g_hash_table_foreach (list->table, gui_size);
gimp_parasite_list_get_memsize_foreach,
&memsize);
}
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object, return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size); 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, static void gimp_pdb_entry_free (gpointer key,
gpointer value, gpointer value,
gpointer user_data); gpointer user_data);
static void gimp_pdb_entry_memsize (gpointer key, static gint64 gimp_pdb_entry_get_memsize (GList *procedures,
gpointer value, gint64 *gui_size);
gpointer user_data);
G_DEFINE_TYPE (GimpPDB, gimp_pdb, GIMP_TYPE_OBJECT) G_DEFINE_TYPE (GimpPDB, gimp_pdb, GIMP_TYPE_OBJECT)
@ -141,10 +140,11 @@ gimp_pdb_get_memsize (GimpObject *object,
GimpPDB *pdb = GIMP_PDB (object); GimpPDB *pdb = GIMP_PDB (object);
gint64 memsize = 0; gint64 memsize = 0;
memsize += gimp_g_hash_table_get_memsize (pdb->procedures); memsize += gimp_g_hash_table_get_memsize_foreach (pdb->procedures,
memsize += gimp_g_hash_table_get_memsize (pdb->compat_proc_names); (GimpMemsizeFunc)
gimp_pdb_entry_get_memsize,
g_hash_table_foreach (pdb->procedures, gimp_pdb_entry_memsize, &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, return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size); gui_size);
@ -452,17 +452,12 @@ gimp_pdb_entry_free (gpointer key,
} }
} }
static void static gint64
gimp_pdb_entry_memsize (gpointer key, gimp_pdb_entry_get_memsize (GList *procedures,
gpointer value, gint64 *gui_size)
gpointer user_data)
{ {
if (value) return gimp_g_list_get_memsize_foreach (procedures,
{ (GimpMemsizeFunc)
gint64 *memsize = user_data; gimp_object_get_memsize,
GList *list; gui_size);
for (list = value; list; list = g_list_next (list))
*memsize += sizeof (GList) + gimp_object_get_memsize (list->data, NULL);
}
} }

View File

@ -209,6 +209,13 @@ gimp_plug_in_manager_finalize (GObject *object)
manager->plug_in_procedures = NULL; 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) if (manager->shm)
{ {
gimp_plug_in_shm_free (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); GimpPlugInManager *manager = GIMP_PLUG_IN_MANAGER (object);
gint64 memsize = 0; gint64 memsize = 0;
memsize += gimp_g_slist_get_memsize (manager->load_procs, 0 /* FIXME */); memsize += gimp_g_slist_get_memsize_foreach (manager->plug_in_defs,
memsize += gimp_g_slist_get_memsize (manager->save_procs, 0 /* FIXME */); (GimpMemsizeFunc)
gimp_object_get_memsize,
gui_size);
memsize += gimp_g_slist_get_memsize (manager->menu_branches, memsize += gimp_g_slist_get_memsize (manager->plug_in_procedures, 0);
0 /* FIXME */); memsize += gimp_g_slist_get_memsize (manager->load_procs, 0);
memsize += gimp_g_slist_get_memsize (manager->locale_domains, memsize += gimp_g_slist_get_memsize (manager->save_procs, 0);
0 /* FIXME */);
memsize += gimp_g_slist_get_memsize (manager->help_domains, memsize += gimp_g_slist_get_memsize (manager->menu_branches, 0 /* FIXME */);
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), memsize += gimp_object_get_memsize (GIMP_OBJECT (manager->interpreter_db),
gui_size); gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (manager->environ_table), memsize += gimp_object_get_memsize (GIMP_OBJECT (manager->environ_table),
gui_size); gui_size);
memsize += gimp_g_list_get_memsize (manager->data_list, memsize += 0; /* FIXME manager->plug_in_debug */
0 /* FIXME */); memsize += gimp_g_list_get_memsize (manager->data_list, 0 /* FIXME */);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object, return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size); gui_size);