> To be clear (for the archives), the above byte-wise copy of the object is 
> only safe if the class has no pointers with ownership
> semantics among its instance variables.  See the discussion of object copying 
> in the Memory Management Guide.

Yes, of course. I took that as a given, based on the way that Ben is recycling 
his objects.

> The init method has nothing to do with zeroing out instance variables.  
> Object allocation is responsible for that.

Indeed.  That's what lies behind the OP's predicament.  If init did it, he 
would not have to hack around like this.  Pity us poor C++ folks.  One of the 
worst design decisions in C++, IMO, is that objects are not zeroed on 
allocation by default.  It leads to constructors like this:

    ivar1 = 0;
    ivar2 = 0;
    ivar3 = 0;
    ivar_p1 = NULL;
    ivar_p2 = NULL;
    ...

Which is tedious and error prone.

Paul Sanders.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to