Re: GIcon thoughts



On Mon, 2008-01-14 at 10:12 +0100, Tim Janik wrote:
> On Thu, 10 Jan 2008, Alexander Larsson wrote:
> 
> > On Wed, 2008-01-09 at 13:53 -0500, Matthias Clasen wrote:
> 
> >> We can't implement the cache using toggle references for 2 reasons:
> >> a) GtkIconSize is a boxed, not an object
> >> b) toggle references only work for a single user, thus they have
> >>    to be reserved for bindings, at least bindable objects.
> >> I propose to instead turn GtkIconInfo into a refcounted boxed object,
> >> and then implement the caching logic for the case that the refcount
> >> drops to one.
> >
> > I'm not sure this is enought, cache-wise. In many cases you'd get a
> > GtkIconInfo, then get the pixbuf for that, save the pixbuf (e.g. in a
> > widget) and unref the info. In fact, it seems unlikely that apps would
> > keep the GtkIconInfo alive for long periods of time. It would be nice if
> > we could get the GtkIconInfo cached until the last ref is dropped to the
> > pixbuf.
> 
> sounds like you should simply keep a reference count from the pixbuf onto
> the corresponding GtkIconInfo. using object data for instance.

Yeah, that might work too.

> > Of course, this is slightly harder, as GdkPixbuf is a public GObject
> > where we can't use toggle references. We could however implement this
> > with some help from the GdkPixbuf implementation. For instance, if we
> > add a resurrect signal to GdkPixbuf and have the dispose()
> > implementation emit this then the cache could connect to this and grab a
> > ref (for some time) before finalization. (The dispose call must also
> > detect that the object is ressurected and avoid chaining to dispose.)
> 
> you're not free to skip chaining in dispose() implementations (just
> like you aren't free to skip chaining in finalize() or anywhere else).
> adding a reference count in dispose is enough to "resurrect" an object
> though, so just do ref(self); in dispose() but don't forget to chain up.
> this'll prevent finalization (finalize() is only called for objects with
> ref_count==0).

Why is that forbidden? You can resurrect things by grabbing a ref, yes,
but if you then chain up it'll free things like user data, etc, which we
don't want in the case of a cache.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]