swarm-support
[Top][All Lists]
Advanced

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

Re: Copying an object in swarm-v.1.0.2 ? (i.e. copy message)


From: Roger M. Burkhart
Subject: Re: Copying an object in swarm-v.1.0.2 ? (i.e. copy message)
Date: Thu, 24 Jul 1997 07:56:08 -0500

> Hi, I have updated my swarm to the version 1.0.2.
> 
> I have a problem that didn't exist with the old swarm version.
> 
>         tMember = [member copy];
> 
> worked fine. (This is to have a duplicate of "member")
> Now I'm getting a runtime error saying the following. Any ideas?
> I've tried to use [member copy: [self getZone]] but didn't work either.
> What is the proper way to copy an object?

This change was made in Swarm 1.0.0 (released in February), so I assume
you were converting from a version older than that.  Please let me know
if you seem to have seen a change after that.

>From the error message you included in your message:

> > ... To allocate, free, or copy objects
> > that use the defined model of zone-based allocation, one of the messages
> > create:, createBegin:/End, drop, or copy: must be used instead.

As Ken Cline already noted, the method you should use to copy the object
is [anObject copy: aZone], but it's your responsibility to provide a method
that implements this message on the objects you want to copy: 

> >    (b) message [anObject copy: aZone] is implemented.
> 
> What I meant to write was:
> 
>      (b) message [anObject copy: aZone] is *not*
>          implemented.
> 
> Sorry about that!
> 
> As I understand it, copy: aZone message may be implemented
> for some classes in the swarm libraries but can *not* be
> inherited by a subclass of SwarmObject.  I'm not sure if
> this is true though.

A default implementation of the copy: message is not currently provided
for reasons noted in previous posts.  You don't automatically inherit an
implementation of copy: from SwarmObject, but you can code one of your own
on your own object class(es) and then continue to inherit from that.  If
all you need is a simple, shallow copy of instance variables, the copy method
you need is nothing more than:  

- copy: aZone
{
  return [aZone copyIVars: self];
}

We don't provide this as a default to avoid errors, since a shallow copy
is not necessarily correct if the object includes any internal allocations.
Rather than provide a possibly erroneous default, we require the programmer
to be explicit by coding the one-line shallow copy method directly.  The
reason for the zone argument on the copy message is that Swarm requires
all objects to be allocated explicitly within some storage zone.

Roger Burkhart
 



                  ==================================
   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]