[FRIAM] [friam-owner at redfish.com: Re: deployable and open source ABMs]
Martin C. Martin
martin at martincmartin.com
Sat Nov 25 21:33:44 EST 2006
Douglas Roberts wrote:
> No, not true. It is because the C++ developer is responsible for
> freeing memory that has been allocated (new, free operators) that C++
> does not need a garbage collector.
>
> In java , memory deallocation is automatic -- it is done by the garbage
> collector. Keeping track of memory that is no longer referenced by the
> running program and therefore needs to be freed is an expensive
> operation that C++ is not burdened with. See
>
> http://www.javaworld.com/javaworld/jw-08-1996/jw-08-gc.html
>
> for more on this topic.
In 1996 Java certainly had many performance problems, and many of those
have been addressed over the last 10 years. O'Reilly's "Java
Performance Tuning" describes the changes from 1.2 to 1.3 as "dramatic."
An article describing the new 1.3 garbage collector is:
www.javaworld.com/javaworld/jw-01-2002/jw-0111-hotspotgc.html
If you're curious how long it's taking in a given app, you can run it
with -verbosegc or -Xloggc:<filename>. There are various free, open
source tools to visualize the results, such as GCViewer:
http://tagtraum.com/gcviewer.html
The wikipedia has a good article on garbage collection. In the section
on performance, it talks about why automatic GC can be slower than
explicit memory management, but also why it can be faster:
"Despite these issues, for many practical purposes,
allocation/deallocation-intensive algorithms implemented in modern
garbage collected languages can actually be faster than their
equivalents using explicit memory management (at least without heroic
optimizations by an expert programmer). A major reason for this is that
the garbage collector allows the runtime system to amortize allocation
and deallocation operations in a potentially advantageous fashion."
It goes on to give an example.
It's also quite possible to explicitly manage memory in a GC language
like Java or LISP. You can allocate an array of objects of your
favourite type, the have a factory method that returns references to
array elements, and a "delete" method so your manager knows when it can
be reused. At the company I work for, ITA Software, our airfare search
engine is written mostly in LISP, with core parts in C++. We use
techniques like that to manage the few classes that are
allocated/deallocated frequently, and use the garbage collector for the
rest. Garbage collection is only a few percent of our runtime.
- Martin
More information about the Friam
mailing list