gtk/docs/reference/gdk-pixbuf/tmpl/refcounting.sgml

82 lines
2.6 KiB
Plaintext
Raw Normal View History

<!-- ##### SECTION Title ##### -->
Reference Counting and Memory Mangement
<!-- ##### SECTION Short_Description ##### -->
Your eyes are bloodshot. Your eyes are bloodshot. Your mouth starts to foam. Your hands are shaking. You know your need your fix. NEED MORE ABSTRACTION! 2000-04-12 Federico Mena Quintero <federico@helixcode.com> This comes from an excellent idea by Tim Janik (timj@gtk.org) to hook to the last unref operation. * gdk-pixbuf/gdk-pixbuf.c (gdk_pixbuf_set_last_unref_handler): New function to set the last unref handler for a pixbuf. (gdk_pixbuf_finalize): New function to actually finalize a pixbuf. It calls the pixbuf's destroy notification function and frees the GdkPixbuf structure itself. (gdk_pixbuf_unref): Use the last unref function of the pixbuf if available. * gdk-pixbuf/gdk-pixbuf-private.h (struct _GdkPixbuf): New fields for the last unref handler and its user data. * gdk-pixbuf/gdk-pixbuf-data.c (gdk_pixbuf_new_from_data): Use g_new0() to allocate the pixbuf. * gdk-pixbuf/gdk-pixbuf-loader.c (gdk_pixbuf_loader_class_init): Fixed the call to gtk_signal_new() for the "frame_done" signal; it was not specifying the `frame' argument. * gdk-pixbuf/gdk-pixbuf-animation.c (gdk_pixbuf_animation_get_width): Fixed docstring. (gdk_pixbuf_animation_get_height): Likewise. (gdk_pixbuf_animation_get_num_frames): Likewise. (gdk_pixbuf_animation_get_frames): Likewise. * doc/gdk-pixbuf-sections.txt: Updated with the new functions and types. * doc/tmpl/gdk-pixbuf.sgml: Added the description for GdkColorspace. * doc/tmpl/scaling.sgml: Added the description for GdkInterpType. * doc/tmpl/refcounting.sgml: Updated with the information about the last unref handler. * doc/tmpl/*.sgml: Markup tweaks. * gdk-pixbuf/Makefile.am (libgnomecanvaspixbuf_la_LDFLAGS): Sigh, update the libtool version number for libgnomecanvaspixbuf as well. (libpixbufloader_*_la_LDFLAGS): The loaders need to be versioned as well, or the old ones won't work with the new stuff. Also, renamed the modules as follows. * gdk-pixbuf/gdk-pixbuf-io.c (gdk_pixbuf_load_module): Now the modules are called "libpixbufloader-<format>.so" instead of "libpixbuf-<format>.so". They needed renaming so that the new loaders won't overwrite the old ones; even with the versioning stuff, the new .so symlink to the .so.1.0.0 would overwrite the old real .so file.
2000-04-13 01:18:41 +00:00
Functions for reference counting and memory management on pixbufs.
<!-- ##### SECTION Long_Description ##### -->
<para>
#GdkPixbuf structures are reference counted. This means that an
application can share a single pixbuf among many parts of the
code. When a piece of the program needs to keep a pointer to a
pixbuf, it should add a reference to it by calling g_object_ref().
When it no longer needs the pixbuf, it should subtract a reference
by calling g_object_unref(). The pixbuf will be destroyed when
its reference count drops to zero. Newly-created #GdkPixbuf
structures start with a reference count of one.
</para>
<note>
<para>
As #GdkPixbuf is derived from #GObject now, gdk_pixbuf_ref() and
gdk_pixbuf_unref() are deprecated in favour of g_object_ref()
and g_object_unref () resp.
</para>
</note>
<para>
<emphasis>Finalizing</emphasis> a pixbuf means to free its pixel
data and to free the #GdkPixbuf structure itself. Most of the
library functions that create #GdkPixbuf structures create the
pixel data by themselves and define the way it should be freed;
you do not need to worry about those. The only function that lets
you specify how to free the pixel data is
gdk_pixbuf_new_from_data(). Since you pass it a pre-allocated
pixel buffer, you must also specify a way to free that data. This
is done with a function of type #GdkPixbufDestroyNotify. When a
pixbuf created with gdk_pixbuf_new_from_data() is finalized, your
destroy notification function will be called, and it is its
responsibility to free the pixel array.
</para>
<!-- ##### SECTION See_Also ##### -->
<para>
#GdkPixbuf, gdk_pixbuf_new_from_data().
</para>
2005-06-20 22:06:27 +00:00
<!-- ##### SECTION Stability_Level ##### -->
<!-- ##### FUNCTION gdk_pixbuf_ref ##### -->
<para>
</para>
@pixbuf:
@Returns:
<!-- ##### FUNCTION gdk_pixbuf_unref ##### -->
<para>
</para>
@pixbuf:
2002-10-11 20:36:21 +00:00
<!-- ##### USER_FUNCTION GdkPixbufDestroyNotify ##### -->
<para>
A function of this type is responsible for freeing the pixel array
of a pixbuf. The gdk_pixbuf_new_from_data() function lets you
pass in a pre-allocated pixel array so that a pixbuf can be
created from it; in this case you will need to pass in a function
of #GdkPixbufDestroyNotify so that the pixel data can be freed
when the pixbuf is finalized.
</para>
@pixels: The pixel array of the pixbuf that is being finalized.
@data: User closure data.