swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: question about copying agents


From: Rick Riolo
Subject: Re: question about copying agents
Date: Wed, 14 Apr 1999 07:46:27 -0400 (EDT)

paul,
its not a question of referenced vs unreferenced,
its a question of references (that is, id or other pointers)
and non-references (that is, doubles, int's and the like).

As you say, copyIVars copies all ivars.  So for
double's, int's and the link it works fine and 
in the only way one might expect.
(I believe it copies ivars from all levels
of the objects superclasses.  if it doesn't
that would be odd and lead to strange results.)
And for anything that is a pointer it also copies the
value in the instance variable, which in this case is
a pointer (reference) to something else (an array of chars,
an object, whatever).   Thus it doesn't make a copy
of that referenced object, it just puts a new pointer
to it in the new object.

And as you say, it gets tricky if you have an object
that has some id's pointing to things you don't want
to make new copies of,eg., the pointer to world and heat 
in heatbugs, and other id's pointing to things you do want 
to make new copies of (eg my example from yesterday,
 and yours below, of some object that contains properties
of the heatbug, say).
I imagine it was issues like this that made the
swarm designer's to decide they'd supply a copyIVars
to do the shallow copy, but leave the deep copy
issues to each implementor, since there is no way
to know generally what needs new copies and what doesn't.

and I agree it should be a method in the Heatbug
(or whatever) that does the copying, eg
-(Heatbug *) cloneMe or -(Heatbug *) cloneBug: (id) bug).
These could of course use copyIVars to get the
ball rolling, then do whatever they need to do
about copying references or making new copies of
referenced objects.

hope this helps.

- r

Rick Riolo                           address@hidden
Program for Study of Complex Systems (PSCS)
4477 Randall Lab                
University of Michigan         Ann Arbor MI 48109-1120
Phone: 734 763 3323                  Fax: 734 763 9267
http://www.pscs.umich.edu/PEOPLE/rlr-home.html

On Tue, 13 Apr 1999, Paul E. Johnson wrote:

> Date: Tue, 13 Apr 1999 21:59:34 -0500
> From: Paul E. Johnson <address@hidden>
> To: address@hidden
> Subject: Re: question about copying agents
> 
> "Marcus G. Daniels" wrote:
> > 
> > >>>>> "PJ" == Paul E Johnson <address@hidden> writes:
> > 
> > PJ> What does "shallow" mean, as opposed to "deep"?
> > 
> > A shallow copy is one where references remain references.  If there is an
> > object referenced in the object that is copied, that referenced will
> > not be copied, merely the reference will be copied.  
> 
> I don't have any really serious reason for asking, but I'm still
> curious.  
> 
> Your answer translated my ignorance from "shallow/deep" to
> "reference/unreferenced".  In looking at an object, I lack a way to
> separate the referenced from the unferenced.  Is the key question
> whether the createBegin/createEnd sequence is called inside an object's
> zone or that pair is executed somewhere else and then a pointer to the
> object is passed over?
> 
> Maybe you could just consider an example such as heatbugs ModelSwarm. It
> creates all those bugs and then sets each one in a list.   If you remove
> one bug and apply copyIVars to it, which IVars would be copied?  I think
> it is safe to say that any non-pointer kind of variable will be copied,
> so all floats, ints, BOOL. Probably also C arrays of those types.
> 
> But objects created in ModelSwarm and set for each individual heatbug
> are not copied. Each heatbug has a variables heat and world. copyIVars
> would not copy the world, since heatbug does not "own" it.  But a copy
> of a heatbug would have a copy of the pointer to the heat and world
> objects?  
>  
> It seems to me this could have important design implications. Suppose
> you want to have heatbugs with objects inside them, say to reflect their
> experience and records.  If you want to be able to copy a heatbug of
> that kind, you would not want to create the record-object in ModelSwarm
> and then pass it in with a "set" method.  Rather, that record-object
> should be created by methods in Heatbug.m, so it would be copied as well
> when the heatbug is copied.
> 
> By how many miles am I missing the barn on this one?
> 
> -- 
> Paul E. Johnson                               email: address@hidden
> Dept. of Political Science                    
> http://lark.cc.ukans.edu/~pauljohn
> University of Kansas                          Office: (785) 864-9086
> Lawrence, Kansas 66045                        FAX: (785) 864-5700
> 
>                   ==================================
>    Swarm-Support is for discussion of the technical details of the day
>    to day usage of Swarm.  For list administration needs (esp.
>    [un]subscribing), please send a message to <address@hidden>
>    with "help" in the body of the message.
> 
> 

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]