Re: OT:C/C++ Opinion Poll




"Jyrki Saarinen" <jyrki@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:fipeq6$e34$1@xxxxxxxxxxxxxxxxxxxxx
Vladimir Vassilevsky <antispam_bogus@xxxxxxxxxxx> wrote:

C++ doesn't have garbage collection, unless you use a 3rd party library.

A language with pointers can't have garbage collection. C++ without
pointers and with garbage collection is called Java.

That is simply not true.

GC in general with C or C++:

http://developers.sun.com/solaris/articles/libgc.html

The GC gurus page:

http://www.hpl.hp.com/personal/Hans_Boehm/gc/

"Performance of the nonincremental collector is typically competitive with
malloc/free implementations. Both space and time overhead are likely to be
only slightly higher for programs written for malloc/free (see Detlefs,
Dosser and Zorn's Memory Allocation Costs in Large C and C++ Programs.) For
programs allocating primarily very small objects, the collector may be
faster; for programs allocating primarily large objects it will be slower.
If the collector is used in a multithreaded environment and configured for
thread-local allocation, it may in some cases significantly outperform
malloc/free allocation in time."

(for the people think that GC implies a problem in performance; there are
even JVM implementations for hard real-time systems, where there is a
guaranteed upper bound for GC CPU usage, though these seem to be
implementations done in the research, at least last time when I looked)

This paints a rather optimistic picture. In reality pointer chasing many
megabytes of memory is what costs you - no matter what GC you choose,
GC performance is directly proportional to the amount of allocated memory.
The only case where garbage collection can be competitive is when you
give it enough memory so that the collector never needs to run...

For a real-world example of the overhead of GC look at GCC. It got twice
as slow when they moved from region based allocation to GC. Furthermore,
despite all the claims, most collectors don't reduce fragmentation at all or
improve locality. Only compacting collectors do, but they are even slower.

Wilco


.



Relevant Pages

  • Garbage Collection in C
    ... Garbage collection is a method of managing memory by using a "collector" ... This memory allocation strategy has been adapted to C by the ... or when explicitely invoked by the programmer. ...
    (comp.lang.c)
  • Re: data allocation in interpreters
    ... What are common techniques for data allocation (strings, ... malloc / free with trying to free unused data as soon as possible. ... I assume "full blown" GC doesn't include reference counting. ... Dijkstra's concurrent collector is my favorite, ...
    (comp.compilers)
  • Re: OT:C/C++ Opinion Poll
    ... A language with pointers can't have garbage collection. ... malloc/free implementations. ... programs allocating primarily very small objects, the collector may be ...
    (comp.arch.embedded)
  • Re: Garbage collection
    ... What exactly would this garbage collection be required to do? ... A conservative collector cannot reliably ... pointers but aren't), and may discard non-garbage data if pointers ...
    (comp.std.c)
  • Re: Garbage collection
    ... What exactly would this garbage collection be required to do? ... A conservative collector cannot reliably ... pointers but aren't), and may discard non-garbage data if pointers ...
    (comp.std.c)