caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] hook before gc major collections
@ 2014-10-07  8:05 Damien Pous
  2014-10-07  8:09 ` Nicolas Boulay
  2014-10-07  9:01 ` Fabrice Le Fessant
  0 siblings, 2 replies; 5+ messages in thread
From: Damien Pous @ 2014-10-07  8:05 UTC (permalink / raw)
  To: caml-list

Hello,

Is there a way to register a function, to be called before each gc
major collection ?
(I have some cache tables which I'd like to empty from time to time -
I'm not sure this is a good idea, but I would like to experiment it.)

I see two related functions in the std lib, but not the precise thing I want:
- Gc.create_alarm, to register a function to be called *after* such
collections ;
- Gc.finalise, which I could use with a dummy heap allocated value,
but then I guess my function would be called before any gc *minor*
collection, which is certainly too often in my concrete use-case.

Thanks in advance,
Damien

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] hook before gc major collections
  2014-10-07  8:05 [Caml-list] hook before gc major collections Damien Pous
@ 2014-10-07  8:09 ` Nicolas Boulay
  2014-10-07  8:42   ` Damien Pous
  2014-10-07  9:01 ` Fabrice Le Fessant
  1 sibling, 1 reply; 5+ messages in thread
From: Nicolas Boulay @ 2014-10-07  8:09 UTC (permalink / raw)
  To: Damien Pous; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1058 bytes --]

Why do you not use "weak" pointer semantic ?
http://caml.inria.fr/pub/docs/manual-ocaml/libref/Weak.html

2014-10-07 10:05 GMT+02:00 Damien Pous <Damien.Pous@inria.fr>:

> Hello,
>
> Is there a way to register a function, to be called before each gc
> major collection ?
> (I have some cache tables which I'd like to empty from time to time -
> I'm not sure this is a good idea, but I would like to experiment it.)
>
> I see two related functions in the std lib, but not the precise thing I
> want:
> - Gc.create_alarm, to register a function to be called *after* such
> collections ;
> - Gc.finalise, which I could use with a dummy heap allocated value,
> but then I guess my function would be called before any gc *minor*
> collection, which is certainly too often in my concrete use-case.
>
> Thanks in advance,
> Damien
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

[-- Attachment #2: Type: text/html, Size: 1794 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] hook before gc major collections
  2014-10-07  8:09 ` Nicolas Boulay
@ 2014-10-07  8:42   ` Damien Pous
  2014-10-07  9:12     ` Virgile Prevosto
  0 siblings, 1 reply; 5+ messages in thread
From: Damien Pous @ 2014-10-07  8:42 UTC (permalink / raw)
  To: caml-list

I would like to, but Weak provides sets while I need maps...
(i.e., I would be somehow happy if Weak.Make did implement Hashtbl.S
rather than Weak.S)

To be more precise, the indices of my maps are hash-consed values, and
I use Jean-Christophe Filliatre's hash-consing library.
In my current code, the maps are thus Patricia trees (Filliatre's Hmap
module) ; it seems non-trivial to reimplement such maps in a
phantomatic way, using Weak in the background.

Do I miss an obvious usage of Weak.S?

Damien

2014-10-07 10:09 GMT+02:00 Nicolas Boulay <nicolas@boulay.name>:
> Why do you not use "weak" pointer semantic ?
> http://caml.inria.fr/pub/docs/manual-ocaml/libref/Weak.html
>
> 2014-10-07 10:05 GMT+02:00 Damien Pous <Damien.Pous@inria.fr>:
>>
>> Hello,
>>
>> Is there a way to register a function, to be called before each gc
>> major collection ?
>> (I have some cache tables which I'd like to empty from time to time -
>> I'm not sure this is a good idea, but I would like to experiment it.)
>>
>> I see two related functions in the std lib, but not the precise thing I
>> want:
>> - Gc.create_alarm, to register a function to be called *after* such
>> collections ;
>> - Gc.finalise, which I could use with a dummy heap allocated value,
>> but then I guess my function would be called before any gc *minor*
>> collection, which is certainly too often in my concrete use-case.
>>
>> Thanks in advance,
>> Damien
>>
>> --
>> Caml-list mailing list.  Subscription management and archives:
>> https://sympa.inria.fr/sympa/arc/caml-list
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] hook before gc major collections
  2014-10-07  8:05 [Caml-list] hook before gc major collections Damien Pous
  2014-10-07  8:09 ` Nicolas Boulay
@ 2014-10-07  9:01 ` Fabrice Le Fessant
  1 sibling, 0 replies; 5+ messages in thread
From: Fabrice Le Fessant @ 2014-10-07  9:01 UTC (permalink / raw)
  To: Damien Pous; +Cc: caml-list

On Tue, Oct 7, 2014 at 10:05 AM, Damien Pous <Damien.Pous@inria.fr> wrote:
> Is there a way to register a function, to be called before each gc
> major collection ?
> (I have some cache tables which I'd like to empty from time to time -
> I'm not sure this is a good idea, but I would like to experiment it.)
>
> I see two related functions in the std lib, but not the precise thing I want:
> - Gc.create_alarm, to register a function to be called *after* such
> collections ;

Isn't *after* a major GC *before* the next one ? The major GC being
incremental, the major collection is almost always already started,
your code running between two slices of the same major collection. So,
it looks like this alarm is catching the only time between the last
slice of a major collection and the first slice of the next one.

--Fabrice

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] hook before gc major collections
  2014-10-07  8:42   ` Damien Pous
@ 2014-10-07  9:12     ` Virgile Prevosto
  0 siblings, 0 replies; 5+ messages in thread
From: Virgile Prevosto @ 2014-10-07  9:12 UTC (permalink / raw)
  Cc: caml-list

Hello,

2014-10-07 10:42 GMT+02:00 Damien Pous <Damien.Pous@inria.fr>:
> I would like to, but Weak provides sets while I need maps...
> (i.e., I would be somehow happy if Weak.Make did implement Hashtbl.S
> rather than Weak.S)
>

I'm not too sure if that apply directly to your case, but you might be
interested in the ephemeron patch
https://github.com/ocaml/ocaml/pull/22, which according to the related
issue in the bts (http://caml.inria.fr/mantis/view.php?id=6353),
should be merged for 4.03 (well, the comment mention "license issues",
that are always longer to solve than expected, but let's stay
optimistic).

Best regards,
-- 
E tutto per oggi, a la prossima volta
Virgile

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-10-07  9:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-07  8:05 [Caml-list] hook before gc major collections Damien Pous
2014-10-07  8:09 ` Nicolas Boulay
2014-10-07  8:42   ` Damien Pous
2014-10-07  9:12     ` Virgile Prevosto
2014-10-07  9:01 ` Fabrice Le Fessant

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).