• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Zeroing out instance variables
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Zeroing out instance variables (From: Ben Haller <email@hidden>)
 >Re: Zeroing out instance variables (From: Ben Haller <email@hidden>)
 >Re: Zeroing out instance variables (From: "Paul Sanders" <email@hidden>)
 >Re: Zeroing out instance variables (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: Zeroing out instance variables
  • Next by Date: Re: Zeroing out instance variables
  • Previous by thread: Re: Zeroing out instance variables
  • Next by thread: Re: Zeroing out instance variables
  • Index(es):
    • Date
    • Thread