------art_28014_13960748.1190214768193
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On 9/19/07, Michael T. Richter <ttmrichter / gmail.com> wrote:
>
>  On Wed, 2007-19-09 at 21:55 +0900, Gone Sail wrote:
>
> true enough.  the copy mechanism of a language that uses garbage collection has no concept of an address .. therefore can only copy the reference.
>
>
> Not all garbage collectors are copying collectors.  Mark/sweep is the
> first one that leaps to mind as a non-copying one.  Baker's Treadmill is
> another.  You'll find lots of other collectors detailed and pointed to here:
> http://www.cs.kent.ac.uk/people/staff/rej/gc.html
>

I'd claim that the presence of and particular implementation of a GC is
orthogonal to the relationship between variables and objects.

In some (many) GC implementations, the physical reference stored in a
variable IS an address, and immediate references like fixnums are
represented by using bits which must be zero in object addresses due to
alignment, (e.g. objects with storage must all be at an even address, so if
the low-order bit is on then the reference is immediate).

Whether or not the GC copies is invisible to the programmer using the
language, this is analogous to the way virtual memory hides the physical
address from the programmer.

Having a GC doesn't preclude copying at the language level, after all that's
what Object#dup does. Of course this shouldn't be confused with assignment
by copying semantics.

One of the things that having a GC does is to make reference semantics safe
from many of the errors which can occur due to botched 'manual' memory
management.  One can certainly implement reference semantics in, say C++, by
using pointers.  One reason that C++ style guides deprecate such practice is
that the bookkeeping of pointer references to avoid either memory leaks or
crashes due to dereferencing a stale pointer is very difficult to get right,
and often more expensive than a garbage collector.  So many C++ projects
adopt a style where objects are copied rather than passed by reference, but
that itself has a cost.

-- 
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

------art_28014_13960748.1190214768193--