Re: GdkPixbuf cache in Nautilus revisited
- From: Alex Larsson <alexl redhat com>
- To: Darin Adler <darin bentspoon com>
- Cc: Gtk Developers <gtk-devel-list gnome org>
- Subject: Re: GdkPixbuf cache in Nautilus revisited
- Date: Fri, 2 Nov 2001 14:11:52 -0500 (EST)
On Fri, 2 Nov 2001, Darin Adler wrote:
> First, a disclaimer. There's something wrong with the Nautilus icon cache
> that makes it not cache was well as it should. This has nothing to do with
> what I'm discussing here, and I'd like to ignore that for now.
>
> As some no-doubt recall, Nautilus has an icon cache with a simple interface.
> It returns GdkPixbuf objects for clients. The clients are not allowed to
> modify the pixbufs, and they unref the pixbufs when they are done with them.
>
> The cache wants to keep around any references to outstanding pixbufs. If a
> client is still keeping the pixbuf around, the cache ought to remember it so
> that other clients can share it.
>
> The cache needs a way to know when the last reference to a pixbuf is
> dropped, either at that moment, or after the fact at the next cache sweep.
> The simpleminded approach is to can peek at the reference count at the time
> of the cache sweep, and see if it's equal to 1 -- if not, there's something
> other than the cache holding a reference, and the pixbuf should not be
> released from the cache. That was the original implementation in Nautilus.
>
> But then we made the reference count in GdkPixbuf be private, so I had to
> ask for a new feature. At that time, there was a lot of discussion about how
> to do this sort of thing. I remember we put a premium on coming up with a
> design that would work with multiple levels of caches. Nautilus was changed
> to use a "last unref" feature.
>
> Before I go back to the dumb "look for reference count of 1 when we sweep
> the cache" algorithm, I was wondering if there is some suitable feature in
> GObject that I should be using for this.
There is:
typedef void (*GWeakNotify) (gpointer data,
GObject *where_the_object_was);
void g_object_weak_ref (GObject *object,
GWeakNotify notify,
gpointer data);
void g_object_weak_unref (GObject *object,
GWeakNotify notify,
gpointer data);
But it seems that this won't let the cache own a ref to the pixbuf so it
can cache it after the last user.
I guess you could make the cache have a strong ref for TIMEOUT seconds,
then drop it in favor of a weak ref. Or something.
/ Alex
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]