• 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: Struct Data Types
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Struct Data Types


  • Subject: Re: Struct Data Types
  • From: Andrew Farmer <email@hidden>
  • Date: Thu, 16 Aug 2007 18:08:52 -0700

On 16 Aug 07, at 17:57, Richard Somers wrote:
Consider the following methods of NSView.

    - (NSRect)frame

    - (NSWindow *)window

And consider the parameter types.

(NSRect) is a pointer to a structure

(NSRect) is a structure; (NSRect *) is a pointer to a structure. A routine with a return type of NSRect returns a rectangle to the caller by writing to a pointer provided by the Objective-C runtime function objc_msgSend_stret.


If this makes no sense, that's OK. You can pretend that structures are being returned just like other variables (int, BOOL, float, ...) - something more clever is happening internally, but the end result is more or less the same.

    (NSWindow *) is a pointer to an object


Why didn't Apple design struct data types like this?

- (NSRect *)frame

Because memory management for structures returned by reference is extremely messy. As structs are not Objective-C objects, they cannot make use of autorelease pools or retain/release counts.
_______________________________________________


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


  • Follow-Ups:
    • Re: Struct Data Types
      • From: Adhamh Findlay <email@hidden>
    • Re: Struct Data Types
      • From: Richard Somers <email@hidden>
References: 
 >Struct Data Types (From: Richard Somers <email@hidden>)

  • Prev by Date: "Esc" doesn't work as a menu item key equivalent
  • Next by Date: Re: Struct Data Types
  • Previous by thread: Struct Data Types
  • Next by thread: Re: Struct Data Types
  • Index(es):
    • Date
    • Thread