Re: Zeroing out instance variables
Re: Zeroing out instance variables
- Subject: Re: Zeroing out instance variables
- From: "Paul Sanders" <email@hidden>
- Date: Sat, 17 Apr 2010 15:13:29 +0100
> 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 (email@hidden)
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:
This email sent to email@hidden