Subj : Re: OO compilers and efficiency To : comp.programming From : Rob Thorpe Date : Thu Jul 21 2005 08:31 am Chris Dollin wrote: > Rob Thorpe wrote: > > > Objects in Java are heap allocated, no matter what they are. There are > > no stack allocated objects as there are in C++. This means that the > > heap must take on the roll filled by both the stack and heap in other > > languages. This means the garbage-collector must waste time cleaning > > up stuff that's gone out of scope that in other languages would be > > dealt with by just moving the stack pointer. > > There's an overhead, but it need not be "cleaning up stuff that's gone > out of scope" (depending on what you eman by "cleaning up"). EG in a > generational collector, it's the non-dead recent stuff that gets copied; > the recent dead stuff is left untouched (of course it leaves a trail, > such as forcing more minor collections and leaving dirty footprints > in the cache). Certainly, better garbage collection strategies can be used, like the generational copying scheme you mention. My point was that moving stack pointers around is a very small amount of overhead indeed compared to even an excellent GC scheme. > [And of course this isn't a property of Java particularly; isn't the > same true in Lisp, Smalltalk, Pop11, SML, OCaml, etc?] No, not all of them. Let's call the commonly used data structures of each of those languages "things", for want of a better word. In many of those languages the compiler can (and will) allocate those things on the stack so long as no pointer to them could possibly leave the context. > > This means that compared to other languages with GC Java relies more on > > it's garbage collector, and of course it has the extra overhead of GC > > unlike C++ and C. > > And it *loses* the overhead of the manual management of both C and C++; > malloc/free or new/delete are not free. Yes, that's true, but malloc and free are generally very efficient. .