On Wed, 06 Oct 2004 17:30:42 -0400, Claude Schneegans
<[EMAIL PROTECTED]> wrote:
> >>Not true. Modern JVMs with JIT compilation techniques are as fast - or
> even faster - than C++ in general.
>
> Kmon, this is mathematically impossible.

I guess you don't know how modern JVMs work? :)

> - whatever "compilation method" is used, the code generated is the same: psudo-code for a virtual machine which must be executed by som machine code program.

The JIT compiler in a JVM can compile the intermediate code to native
code on first execution - subsequent executions are of the native code
instead. HotSpot compilers (like Sun's) can compile "commonly
executed" code or optimize code based on execution paths etc etc. The
compile-on-demand technology is pretty sophisticated these days and
raw Java performance really isn't an issue any more...

> - C (or C++) generates directly machine code.

It depends on the compiler. There are C and C++ compilers that target
virtual machines for example. Some compilers output intermediate code
that another converts into machine code, some output assembler and use
the system's assembler program to convert that to native code. Some
C++ compilers translate to C code and use the system's C compiler to
compile that and so on.

Compiler technology is how I cut my teeth. Computer language design
and implementation was my postgraduate research subject and the first
commercial projects I worked on were code generators and optimizers. I
worked on compilers and compiler technology for about ten years before
I moved into mobile phone infrastructure and later to the web so it's
quite a passion of mine :)

> Right, but if an application relies on those differences, it is because they are system dependant,
> and chances are great they are not available at all in Java anyway.

You'd be surprised - an awful lot of C / C++ developers just don't
know how to write portable code! I made a lot of money off that lack
of knowledge in the early 90's :)

> Java is interpreted, every instruction is validated before it is executed, so pointers could be verified too.

If we ever meet for a beer, I'll explain to you just how much work is
involved to actually verify C-style pointers at runtime and the
penalties it imposes. The ANSI C reference implementation can actually
check pointers at execution time but you wouldn't want to run big
complex applications on it except to check their behavior, because of
the performance overhead.

> Java could be THE solution for pointers problems, but instead of providing the advantage of pointers
> together with a solution for the problem, they completely removed pointers... dumb... :-(

To be accurate, they didn't remove them - they hid them in reference types:

Thing t = new Thing();

t is absolutely a pointer. It's more like Pascal's pointers in that
it's restricted to existing objects (heap or stack) and can't wander
all over memory like a C / C++ pointer can. Consequently you can't do
pointer arithmetic on Java 'pointers', just like in Pascal.

C++ requires one of the following:

Thing* t = new Thing;
Thing& t = *new Thing;

The latter lets you refer to the allocated Thing via plain t - the
former requires you say *t. Of course, in C++ I can also say:

unsigned char[256] memory;
Thing* t = new (memory) Thing;

which allocates the Thing object on top of the memory variable. You'd
still need to call the destructor explicitly (by deleting t).

> Well, just managed them! Java manages everything, why not pointers?

Technically, it does - see above.

Anyway, this is wandering well off topic so we should probably take
the discussion elsewhere...
--
Sean A Corfield -- http://www.corfield.org/
Team Fusebox -- http://www.fusebox.org/
Got Gmail? -- I have 2 invites

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to