On Apr 16, 2010, at 5:34 PM, Paul Sanders wrote:

> Another way might be to provide a method in each class or subclass called, 
> say, zeroIVars and code it as (typed in mail):
> 
> - (void) zeroIVars
> {
>    static ThisClass *clean_instance_of_this_class;
> 
>    assert ([self isMemberOfClass: [ThisClass class]);
>    if (clean_instance_of_this_class == nil)
>        clean_instance_of_this_class = [[ThisClass alloc] init];
>    *self = *clean_instance_of_this_class;
> }

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.

> This approach gives you the opportunity to end up with an object that is not 
> just all zeroes (by way of the init method)

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

Regards,
Ken

_______________________________________________

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