caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Guillaume Yziquel <guillaume.yziquel@citycable.ch>
To: orbitz@ezabel.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Scoped Bound Resource Management just for C++?
Date: Wed, 9 Feb 2011 01:46:24 +0100	[thread overview]
Message-ID: <20110209004623.GF12473@localhost> (raw)
In-Reply-To: <50AF76A1-30E0-4735-AFB2-88BB603899CE@ezabel.com>

Le Tuesday 08 Feb 2011 à 18:57:37 (-0500), orbitz@ezabel.com a écrit :
> One of the benefits, in my opinion, of C++ is SBRM.  You can reason
> about the lifetime of an object and have an give yourself guarantees
> about its clean up.  The method of initialization and clean up are
> also consistent for every object in the language.

I assume you're talking about destructions of temporaries and auto
variables in C++. To me, the main benefit of this appears when you're in
a procedurally oriented language and when the language idiom allows you
to pass your objects in registers when they are small enough, or relying
on compiler optimisations to avoid copying the objects over and over
between function calls. The downside is that as soon as you're crossing
boundaries between libraries or putting things on the freestore, there
is copying involved, and not-so-clear memory management semantics.

> My questions are:
> 1) Do other people in the FP world consider this to be a good
> strategy?

Not to my opinion. To me, the way OCaml manages the garbage collection
of the minor heap seems to me a more practical way of doing things and
not an inefficient one. Moreover, SBRM makes memory management semantics
not so easy to reason about when integrating C++ with an another
language or another runtime (callbacks from C++ for instance).

> 2) Can this be done in a sane way in a GCd language?

Nothing stops you from managing the lifecycle of your values
explicitely, but I do not think you'd reap the benefits above. Moreover,
from a GC point of view, I do not see how to implement an SBRM-friendly
scheme compatible with heap compacting GC algorithms like the modified
Cheney algorithm used in OCaml.

For integral types, you have SBRM quite for free in OCaml, but anything
more complex either gets optimised away if possible, or gets quickly
heap allocated (much more likely).

> 3) What are the alternatives in a language like Ocaml?

I think you would also have a typing issue in a language such as OCaml.
Having SBRM-managed values means not being able to constructs lists with
them or things like that. So each time you call a function with such a
value in parameter, you'd need the compiler to guarantee that it would
not try to heap allocate it. Otherwise, you're back with copying the
value.

I think your question depends on what kind of datatypes you're
interested in, what kind of lifecycle you expect from your values, and
what runtime benefits you expect of it.

If your value is short-lived, it is allocated on the minor heap, never
moves from there, and garbage collection of the minor heap is very fast.
That's the closest you can get, I guess. But you do not have guarantees
of it being garbage collected, unless you trigger manually garbage
collection of the minor heap (which may be costly if done in an
unreasonable manner).

> Thanks!


-- 
     Guillaume Yziquel


  reply	other threads:[~2011-02-09  0:48 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-08 23:57 orbitz
2011-02-09  0:46 ` Guillaume Yziquel [this message]
2011-02-09  0:48 ` Jacques Garrigue
2011-02-09  6:25 ` dmitry grebeniuk
2011-02-09 12:01 ` rossberg
2011-02-09 15:15   ` orbitz
2011-02-09 16:14     ` Gerd Stolpmann
2011-02-09 16:52       ` David Rajchenbach-Teller
2011-02-09 17:54         ` orbitz
2011-02-09 21:50           ` Jon Harrop
2011-02-10  8:10           ` David Rajchenbach-Teller
2011-02-10 10:39     ` Guillaume Yziquel
2011-02-10 10:59       ` Guillaume Yziquel
2011-02-09 19:11   ` Florian Weimer
2011-02-09 20:10     ` Andreas Rossberg
2011-02-09 20:45       ` Florian Weimer
2011-02-09 21:12         ` Andreas Rossberg
2011-02-10 21:31           ` Florian Weimer
2011-02-09 18:03 ` Jon Harrop
2011-02-09 20:47 ` Norman Hardy
2011-02-09 21:00   ` Gabriel Scherer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110209004623.GF12473@localhost \
    --to=guillaume.yziquel@citycable.ch \
    --cc=caml-list@inria.fr \
    --cc=orbitz@ezabel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).