• 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: Garbage collector vs variable lifetime
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Garbage collector vs variable lifetime


  • Subject: Re: Garbage collector vs variable lifetime
  • From: Ricky Sharp <email@hidden>
  • Date: Sat, 7 Jun 2008 14:43:18 -0500


On Jun 7, 2008, at 1:30 PM, Michael Ash wrote:

On Sat, Jun 7, 2008 at 9:59 AM, Ricky Sharp <email@hidden> wrote:
Finally, I think that usages of NSMutableData may also be a bit tricky. In
my case I'll probably just obtain a copy of its bytes, manipulate them and
then copy the result back in. Sort of ironic though in that the inner
pointer would have been valid anyhow in such blocks of code (the
NSMutableData instance would be around between the get and subsequent set of
its bytes):


NSMutableData* data = [...];
const unsigned char* bytes = [data bytes];
operate on copy of bytes in GC-aware buffer
[data replaceBytesInRange:...];

This is unnecessary, since data is guaranteed to stay live throughout your operation because you use it at the end. You only need to take measures when your last reference to the NSData object comes before your last reference to its bytes pointer.


That's why I called it 'ironic' in my description. The block above messages data at the end, so yes, no need to do the copies. But, code that typically just works on the mutableBytes would be:

NSMutableData* data = [...];
unsigned char* bytes = [data mutableBytes];
operate on bytes

Here, we have the same issue.
___________________________________________________________
Ricky A. Sharp         mailto:email@hidden
Instant Interactive(tm)   http://www.instantinteractive.com

_______________________________________________

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: 
 >Garbage collector vs variable lifetime (From: Quincey Morris <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Bill Bumgarner <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Antonio Nunes <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Ken Thomases <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Bill Bumgarner <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Ken Thomases <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: "Michael Ash" <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: "Hamish Allan" <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: "Michael Ash" <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Ricky Sharp <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: "Michael Ash" <email@hidden>)

  • Prev by Date: Java and Objective-C
  • Next by Date: Re: Garbage collector vs variable lifetime
  • Previous by thread: Re: Garbage collector vs variable lifetime
  • Next by thread: Re: Garbage collector vs variable lifetime
  • Index(es):
    • Date
    • Thread