Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are the synthesized ivars stored?

I've been reading up on the automatically synthesized ivars. My question is, "WHere are automatically they allocated?" I would have expected them to be part of self, so that I could see them in the debugger, but it seems that the only way I can see them is by invoking the accessor method (via the gdb 'po' command). Isn't there space in the class/object's struct (as there would be for an explicitly declared ivar)?

(Is there a description of the in-memory representation for a modern Objective-C object?)

Being a C guy, it makes me very uncomfortable to not to be able to see where everything is. :-P

like image 341
wrlee Avatar asked May 22 '11 18:05

wrlee


2 Answers

Looks like this will tell you: How do automatic @synthesized ivars affect the *real* sizeof(MyClass)?

I am a C guy at heart too. Why bother using these auto generated ones? I like looking at a class and seeing what it holds onto in terms of data.

Interesting: Neat how they took the 64 bit change to make things better. http://www.sealiesoftware.com/blog/archive/2009/01/27/objc_explain_Non-fragile_ivars.html

like image 130
Tom Andersen Avatar answered Nov 19 '22 22:11

Tom Andersen


They are added to the objective-c object (which is a C structure) no different to a regular ivar, so for example:

@interface TestObject : NSObject {

}

@property (nonatomic, assign) int theInt;

@end

@implementation QuartzTestView

@synthesize theInt;

@end

You can refer to theInt ivar directly (not through property accessors) either:

- (void)someMethod {
    theInt = 5;
}

OR

- (void)someOtherMethod {
    self->theInt = 10;
}
like image 26
Stuart Carnie Avatar answered Nov 19 '22 20:11

Stuart Carnie