I have a new object inherited from NSObject
Car *myCar = [[Car alloc] init];
This returns 16, the size of a Car object
printf("myCar object: %d\n", sizeof(*myCar));
plz help me to make it clear, thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
sizeofin this case works like C.As bbum said, you should not use
sizeofonNSObjecttypes (but pointers toNSObjects are ok). Clang forbids requesting thesizeofand object. The objc runtime should be your reference if you need an object’s size because the actual size of an objc object is not a static (compile-time) value, it is determined at runtime.Given these types:
And these messages:
On 64 bit, we get:
And on 32 bit, we get:
There’s a little example which shows you why sizes grow. For more detail, here is the wikipedia page.