From: Christopher Stacy
Subject: cloning
Date: 
Message-ID: <uelqv2hpf.fsf@spacy.Boston.MA.US>
Frequent questions on this newsgroup concern how to "clone" 
or copy an object.  I've been programming for 28 years, and can't
easily think of any cases where that's exactly what I wanted to do.
I either create a new object with exactly the same parameters,
using the object creation function; or else I use some kind of
merging function which knows how to get just the right parts out 
of the original object and combine them with the differing parts.

Once I have the object(s), if I want to know if two things are really
the same thing, I do a pointer comparison (EQ), and if I want to know
if two distinct things have the same meaning, I use a domain-specific
operator that tells me this.  What else could possibly know the answer?

If we're talking about conveying an object across instance environments
(eg. "serializing" them), then other issues come up that would seem to
be beyong the scope of mere copying or cloning.

So, rather than asking how cloning is handled in other languages,
or discussing the kinds of protocols that could be invented for
doing this in Lisp or in general, I have a different question.

Why does anyone think they want to do this?
From: Frank A. Adrian
Subject: Re: cloning
Date: 
Message-ID: <3B695761.B80265FE@qwest.net>
Christopher Stacy wrote:

> Why does anyone think they want to do this?

Here is one example that I've been dealing with in a C++ program :-(.

We have a multi-threaded application that involves pattern matching. 
The main thread reads a textual representation of a set of patterns and
turns it into a tree of precompiled interpreted data with nodes dangling
off it that access the objects to be matched against.  The access and
compilation of the file takes a fair amount of time.

Each worker thread needs to access the parse tree in order to scan its
set of objects.  In order to reduce access conflict and locking we use a
clone method on the interpeted tree to produce a local copy for each
worker thread.

One could say, "Why not just put the parsing code in the worker thread
and have each thread compile its own interpreted tree?"

The answer: The patterns to be searched for change.  When they change it
is extremely important that the worker threads be paused for updating
the interpreted structure for the shortest amount of time possible.  As
such, we do the parsing and interpreted tree generation in the main
thread and then notify the worker threads that they have to reload the
interpreted tree.  They again use the clone method to do so.  This takes
much less time than having each worker thread parse and construct the
interpreted data on its own.

faa