Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful
Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful
- Subject: Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful
- From: glenn andreas <email@hidden>
- Date: Wed, 6 Feb 2008 14:23:26 -0600
On Feb 6, 2008, at 11:05 AM, Jean-Daniel Dupas wrote:
Structures don't have "magic invisible members":
@interface Foo {
}
@end
Foo *aFoo;
NSLog(@"Foo is a %@", aFoo->isa);
Notice how there is an "isa" member that is automatically put
there, not unlike the way that a C++ object might have a vtable (or
other internal plumbing for multiple inheritance).
Wrong. This will not work. Foo will not have a magic isa ivar, an is
not a valid objc class.
You have to either:
1) inherit from a valid root class (NSObject).
2) add a "Class isa" ivar to your declaration.
See the NSObject declaration:
@interface NSObject <NSObject> {
Class isa;
}
...
@end
Mea culpa - someday I'll learn to not post until the _second_ cup of
coffee....
Perhaps a more accurate statement is that it has an "explicit magic
member" - it must have an isa pointer as the very first field
(contrary to the caffeine deprived ruminations, the compiler doesn't
put it there automatically).
Regardless, all objects must start with that isa pointer - the runtime
requires it. Objects _are_ special, and pretending that this is just
another arbitrary struct is incorrect:
1) They can't live on the stack
2) They have a special isa pointer
3) They have implicit requirements to be allocated/copied/released
using special routines (NSAllocateObject, NSCopyObject,
NSDeallocateObject) - i.e., it's unclear if you attempted to malloc or
new a structure of the same type and manually filled in the isa
pointer would necessarily work on current or future Objective-C
runtimes (it would almost certainly fail under 64 bit Objective 2.0)
Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
quadrium | prime : build, mutate, evolve, animate : the next
generation of fractal art
_______________________________________________
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