Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Q: automatic forgetting cache, module Weak, Gc control
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-07-01 (13:59)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Q: automatic forgetting cache, module Weak, Gc control
On Thu, 2004-07-01 at 18:43, Jacques GARRIGUE wrote:
[caching results]

A more labor intensive idea would be to manage the
caches yourself. This has the advantage -- and disadvantage --
that you're totally in control.

One idea -- just use a fixed sized cyclic buffer,
keep usage stats, and manually tune the buffer sizes.

Another more flexible and potentially expensive
technique is to cache everything in a thread-safe
manner, and run a separate 'reaper' thread to purge
the most useless values. This has the advantage that
the cache control is lexically isolated and so 
can be worked on independently. Obviously needing
to use a thread-lock to put values in the cache
will cost big time. 

The big plus here is that you can
actually tune the reaping dynamically .. that is,
whilst the program is actually running.
If you really want to get fancy you could actually
make a second thread that output usage stats on 
a socket, and collect them in some kind of crude
dynamic graph you could watch, so as to understand
the loading better.

I'm NOT recommending this technique over using
Weak/GC tuning, I think you should try that first
since it integrates seamlessly with the actual
memory management system.

John Skaller,
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: