Version française
Home     About     Download     Resources     Contact us    
Browse thread
C++ STL bindings
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Basile Starynkevitch <basile@s...>
Subject: Re: [Caml-list] C++ STL bindings
On Mon, May 10, 2010 at 10:00:32AM -0400, Jianzhou Zhao wrote:


> Does anyone know if there is an OCaml binding to C++ STL libraries, or
> any other functional language with a foreign binding to such C++
> standard libraries (STL, boost)?

I believe such a beast cannot reliably exist.

The STL C++ library (and probably the Boost one also) provides a bunch
of data structure implementations in C++. All these implementation are
built on the (sad) fact that C++ manage memory (& resources)
explicitly. In other words, any data in the C++ heap was probably
allocated thru new and should probably be *explicitly* freed thru
delete.

Also the STL C++ library is heavily template based. This means some
kind of systematic code generation.

In contrast, Ocaml provide very useful generic abstract data types in
its standard library (and other common libraries...) using functors
(see the List, Array, Hashtbl, Map, Set, ... modules).

Ocaml has also a powerful garbage collector, and most functors from
its standard library take advantage of it (in a few words, in Ocaml,
allocating memory is conceptually quite cheap & efficient, and you
don't need to free it explicitly; in contrast, allocating memory
inside C++ heap is usually much slower that equivalent allocation in
Ocaml; of course the C++ memory manager has features not provided by
Ocaml's GC -real multithreading, ...-).


So the short answer to your quest is: stick to Ocaml functors (and
avoid using C++ STL in Ocaml programs).


Cheers.

-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***