Version française
Home     About     Download     Resources     Contact us    
Browse thread
Weak hashtables & aggressive caching
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] Weak hashtables & aggressive caching
From: Matt Gushee <matt@gushee.net>

> I wrote a LablGTK-based image viewer this past weekend; one of its 
> features is an image cache--specifically, a weak hashtable that contains
> values of type string * GdkPixbuf.pixbuf (the string being the file 
> name). When a particular image file is requested, it is retrieved from 
> the cache if it exists there; otherwise it is loaded from disk (and 
> placed in the cache at the same time). This is useful if the user wants 
> to quickly look back through a series of images that have already been 
> loaded, but it doesn't help with loading images for the first time.

I wonder how you trigger the GC, to both keep the cache long enough,
and to avoid filling the memory too much, and resulting in lots of
swapping.

With ocaml data structures, the GC does a good job, as it is
triggered everytime already allocated memory is filled. Hopefully this
means that the memory set should not increase. But with external data
structures like pixbufs, the GC is called in a pre-programmed way,
currently at least after every 10 pixbuf allocations. This is probably
too much for your scheme (you won't get more than 9 images in memory),
but less might be not enough (big images will fill the memory without
calling the GC earlier.)

Considering the difficulties avoid memory overflow, the only workable
approach still seems to have an over-eager GC, that happens much more
often than necessary. But as a result the caching effect is very
limited. Otherwise you need to change all the parameters in lablgtk.

Jacques Garrigue