• 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: GC, plain C structs, and when to use __strong
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GC, plain C structs, and when to use __strong


  • Subject: Re: GC, plain C structs, and when to use __strong
  • From: "Clark S. Cox III" <email@hidden>
  • Date: Wed, 22 Sep 2010 13:33:17 -0700

On Sep 21, 2010, at 4:13 PM, Quincey Morris wrote:

> On Sep 21, 2010, at 15:37, Sean McBride wrote:
>
>> If I have a plain C struct that contains some Obj-C object pointers like:
>>
>> struct {
>> int boring;
>> NSString* string;
>> } MyStruct
>>
>> What must I do to be safe in GC?
>>
>> a) I know I must allocate my structs using NSAllocateCollectable and
>> NSScannedOption.
>> b) I'm pretty sure I don't need a '__strong' in my struct declaration.
>> (doc say "__strong is implicitly part of any declaration of an Objective-
>> C object reference type.")
>> c) I'm pretty sure if I use a pointer to this struct as an ivar, I must
>> tag it with __strong.
>
> At risk of getting myself into trouble, I'd say correct, correct and correct.
>
>> d) I'm not sure about passing pointers to this struct around.  Need I
>> tag all parameters and return values as __strong too?  ex:
>>
>> void DoThing (__strong MyStruct* param) { ... }
>
> At ditto risk, I'd say no to '__strong'. Variable 'param' is a stack variable is therefore a *root* reference, and as such the concept of strong or weak doesn't apply. (That is, AFAIK, applying '__strong' or '__weak' to a stack variable *never* has any effect on its behavior in any way.)

Correct. As roots, the stack and registers (i.e. all ways that a parameter could be passed) are *always* effectively strong.


--
Clark S. Cox III
email@hidden

_______________________________________________

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: 
 >Re: GC, plain C structs, and when to use __strong (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: What's the point of @properties?
  • Next by Date: Re: NSTableView display issue
  • Previous by thread: Re: GC, plain C structs, and when to use __strong
  • Next by thread: Need functionality of CAShapeLayer in 10.5
  • Index(es):
    • Date
    • Thread