Re: C++ implementation of core Java API
On Nov 3, 3:21 pm, Lew <l...@lewscanon.com> wrote:
James Kanze wrote:
garbage collection.) What you want to do is to "adapt" the Java
API to C++, taking what's good in it, and adapting it to the C++
idiom.
Roland Pibinger wrote:
That's the point. Adapt the Java API to C++ idioms. You can do the
same in C++ with pointers what you can do with references in Java. As
long as you don't try to copy the container the differences are minor.
Of course, in C++ you always have to take ownership into
consideration.
Some years back I worked on a multi-threaded C++ app. I wrote
C++ versions of Java's Thread and Runnable classes for it,
based on a freely-available pthreads library.
It turned out that it was tricky to get the semantics to
match, in part because a C++ reference (type&) is not the same
as a Java reference.
That's because Java's references are really what C++ calls
pointers. Most earlier C++ threading libraries had pretty much
the same interface as the Java one.
Also tricky was to get Thread to be startable on its own or
with a Runnable argument.
What was the problem? It always seems pretty trivial to me.
The big problem in C++ without garbage collection is managing
the lifetime of the thread object of a detached thread. Mainly
because the lifetime is largely irrelevant except for memory
management issues. But there are solutions which work there as
well, and for the most part, if you want to support clean
shutdown, you'll need to use them anyway.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34