Commit f274dce2 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

added new function gimp_g_value_get_memsize() that attempts to calculate

2004-07-13  Sven Neumann  <sven@gimp.org>

	* app/core/gimp-utils.[ch]: added new function
	gimp_g_value_get_memsize() that attempts to calculate the memory
	requirements for a GValue.

	* app/text/gimptextundo.c (gimp_text_undo_get_memsize): use the
	new function to obtain a better estimate for the size of the text
	undo.
parent 11795e78
2004-07-13 Sven Neumann <sven@gimp.org>
* app/core/gimp-utils.[ch]: added new function
gimp_g_value_get_memsize() that attempts to calculate the memory
requirements for a GValue.
* app/text/gimptextundo.c (gimp_text_undo_get_memsize): use the
new function to obtain a better estimate for the size of the text
undo.
2004-07-13 Sven Neumann <sven@gimp.org>
* app/tools/gimptexttool.c (gimp_text_tool_create_layer): plugged
......
......@@ -27,6 +27,8 @@
#include "core-types.h"
#include "config/gimpconfig-types.h"
#include "gimp-utils.h"
......@@ -99,6 +101,39 @@ gimp_g_list_get_memsize (GList *list,
return g_list_length (list) * (data_size + sizeof (GList));
}
gint64
gimp_g_value_get_memsize (GValue *value)
{
gint64 memsize = sizeof (GValue);
if (G_VALUE_HOLDS_STRING (value))
{
memsize += strlen (g_value_get_string (value)) + 1;
}
else if (G_VALUE_HOLDS_BOXED (value))
{
if (GIMP_VALUE_HOLDS_COLOR (value))
{
memsize += sizeof (GimpRGB);
}
else if (GIMP_VALUE_HOLDS_MATRIX2 (value))
{
memsize += sizeof (GimpMatrix2);
}
else
{
g_warning ("%s: unhandled boxed value type: %s",
G_STRFUNC, G_VALUE_TYPE_NAME (value));
}
}
else if (G_VALUE_HOLDS_OBJECT (value))
{
g_warning ("%s: unhandled object value type: %s",
G_STRFUNC, G_VALUE_TYPE_NAME (value));
}
return memsize;
}
/*
* basically copied from gtk_get_default_language()
......
......@@ -39,6 +39,7 @@ gint64 gimp_g_slist_get_memsize (GSList *slist,
gint64 data_size);
gint64 gimp_g_list_get_memsize (GList *list,
gint64 data_size);
gint64 gimp_g_value_get_memsize (GValue *value);
gchar * gimp_get_default_language (const gchar *category);
......
......@@ -27,6 +27,7 @@
#include "core/gimpitem.h"
#include "core/gimpitemundo.h"
#include "core/gimp-utils.h"
#include "gimptext.h"
#include "gimptextlayer.h"
......@@ -199,15 +200,11 @@ gimp_text_undo_get_memsize (GimpObject *object,
GimpTextUndo *undo = GIMP_TEXT_UNDO (object);
gint64 memsize = 0;
if (undo->pspec)
{
/* this is incorrect, but how can it be done better? */
memsize = sizeof (GValue);
}
else if (undo->text)
{
memsize = gimp_object_get_memsize (GIMP_OBJECT (undo->text), NULL);
}
if (undo->value)
memsize += gimp_g_value_get_memsize (undo->value);
if (undo->text)
memsize += gimp_object_get_memsize (GIMP_OBJECT (undo->text), NULL);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment