caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Finalization and object dependencies
@ 2005-11-11 14:41 Florian Weimer
  2005-11-11 18:00 ` [Caml-list] " Damien Doligez
  2005-11-17  1:42 ` Stefan Monnier
  0 siblings, 2 replies; 4+ messages in thread
From: Florian Weimer @ 2005-11-11 14:41 UTC (permalink / raw)
  To: caml-list

I've got to different types of objects, say database tables and
cursors for one table.  Caml code is expected to access these objects
using some handle reference.

  * If the GC detects that no handles for a particular cursor exist
    anymore, the underlying cursor object should be closed (which may
    free external resources such as locks).  At this time, all "equal"
    handles become invalid, subsequent operations will fail.

  * If the GC detects that no handles for some table object exist, and
    there are no handles for that table, this table is closed.
    Subsequent operations on "equal" table handles will fail.
    
  * The user may explicitly close a cursor handle.  In this case, the
    underlying object is closed, and the handle is marked invalid.
    (Same as above.)

  * The user may explicitly close a table handle.  In this case, all
    cursor which are still open are closed.  Future operations on
    them, or the table, will fail.

  * When the program exits, all cursors and tables shall be closed,
    even if the program was termined by an exception.

(Here, "to fail" means to raise an exception or some other kind of
deterministic error signaling mechanism.)

Usually, application code will gracefully close all cursors, and the
table, but I want my library to be as safe as possible to use, and
avoid random crashes or memory leaks.

There are a couple of approaches to implement the desired behavior:

  (1) Just use weak arrays of tables and cursor, together with Gc.alarm.

  (2) Use Gc.finalise for handler objects which contain an index into
      (plain) arrays of tables and cursors.  Use reference counting
      (or back pointers) to prevent premature finalization of table
      objects while there are still cursors around.

  (3) Same as (2), but using custom blocks and C code.

  (4) Some hybrid approach.

I'm not exactly happy with each appraoch because it seems I must
implement a simple memory manager on my own for managing the array
elements.  Perhaps I'm missing something?

How is the performance of the three approaches?  Each one uses a
different GC mechanism to achieve its goals, so I'm a bit puzzled.


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

end of thread, other threads:[~2005-11-17  1:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-11 14:41 Finalization and object dependencies Florian Weimer
2005-11-11 18:00 ` [Caml-list] " Damien Doligez
2005-11-12 18:22   ` Florian Weimer
2005-11-17  1:42 ` Stefan Monnier

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).