Re: Struct Data Types
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