FROM : Bill Bumgarner
DATE : Sun Feb 17 21:17:51 2008
On Feb 17, 2008, at 12:03 PM, Sherm Pendley wrote:
> Why would the parent's size be hard-coded? You can get the size of
> the parent at run time, by dereferencing a couple of levels into
> isa. All the compiler would have to do is emit code that walks down
> isa to get the parent's size, and add it to self to establish a base
> address. The only hard-coded offsets would then be relative to that
> base, for the current class' own ivars.
>
> Changing the size of the parent class wouldn't break such a scheme,
> so far as ordinary usage goes. People playing games with sizeof() or
> @defs deserve whatever breakage they get. :-)
>
> Doesn't the current (I refuse to call it "legacy" quite yet...) 32-
> bit compiler emit code like that when ivars are accessed?
To dive a little deeper, consider the instance variables for NSView,
including inherited ivars. Well, a subset, really:
@interface NSObject <NSObject> {
Class isa;
}
@interface NSResponder : NSObject <NSCoding>
{
id _nextResponder;
}
@interface NSView : NSResponder
{
NSRect _frame;
NSRect _bounds;
id _superview;
id _subviews;
NSWindow *_window;
}
Within the legacy runtime ;), the memory for NSView looks just like a
C struct with this layout:
struct NSViewLikeStruct {
Class isa;
id _nextResponder;
NSRect _frame;
NSRect _bounds;
id _superview;
id _subviews;
NSWindow *_window;
};
So, in the implementation of an NSView, an access to an instance
variable -- say _subviews -- is compiled down to something equivalent
to:
((struct NSViewLikeStruct *) aView)->_subviews
Now, if an instance variable is added to NSObject or NSResponder and
the subclasses are not compiled, the above code will have the wrong
offset.
This is fragile, but allows instances to be allocated as a single
chunk of memory while also reducing the amount of metadata and/or
indirection required to get at any given instance variable's slot.
To fix the issue, it has to be done partially at runtime and requires
a different layout for the instances...
b.bum
DATE : Sun Feb 17 21:17:51 2008
On Feb 17, 2008, at 12:03 PM, Sherm Pendley wrote:
> Why would the parent's size be hard-coded? You can get the size of
> the parent at run time, by dereferencing a couple of levels into
> isa. All the compiler would have to do is emit code that walks down
> isa to get the parent's size, and add it to self to establish a base
> address. The only hard-coded offsets would then be relative to that
> base, for the current class' own ivars.
>
> Changing the size of the parent class wouldn't break such a scheme,
> so far as ordinary usage goes. People playing games with sizeof() or
> @defs deserve whatever breakage they get. :-)
>
> Doesn't the current (I refuse to call it "legacy" quite yet...) 32-
> bit compiler emit code like that when ivars are accessed?
To dive a little deeper, consider the instance variables for NSView,
including inherited ivars. Well, a subset, really:
@interface NSObject <NSObject> {
Class isa;
}
@interface NSResponder : NSObject <NSCoding>
{
id _nextResponder;
}
@interface NSView : NSResponder
{
NSRect _frame;
NSRect _bounds;
id _superview;
id _subviews;
NSWindow *_window;
}
Within the legacy runtime ;), the memory for NSView looks just like a
C struct with this layout:
struct NSViewLikeStruct {
Class isa;
id _nextResponder;
NSRect _frame;
NSRect _bounds;
id _superview;
id _subviews;
NSWindow *_window;
};
So, in the implementation of an NSView, an access to an instance
variable -- say _subviews -- is compiled down to something equivalent
to:
((struct NSViewLikeStruct *) aView)->_subviews
Now, if an instance variable is added to NSObject or NSResponder and
the subclasses are not compiled, the above code will have the wrong
offset.
This is fragile, but allows instances to be allocated as a single
chunk of memory while also reducing the amount of metadata and/or
indirection required to get at any given instance variable's slot.
To fix the issue, it has to be done partially at runtime and requires
a different layout for the instances...
b.bum
| Related mails | Author | Date |
|---|---|---|
| Randall Meadows | Feb 11, 22:14 | |
| Melissa J. Turner | Feb 11, 22:27 | |
| Kyle Sluder | Feb 11, 22:28 | |
| Joshua Emmons | Feb 11, 22:29 | |
| Shawn Erickson | Feb 11, 22:33 | |
| j o a r | Feb 11, 22:35 | |
| Brian Christensen | Feb 11, 22:38 | |
| Randall Meadows | Feb 11, 22:56 | |
| Jens Alfke | Feb 11, 23:11 | |
| Kyle Sluder | Feb 11, 23:32 | |
| j o a r | Feb 11, 23:53 | |
| Adam P Jenkins | Feb 12, 00:33 | |
| Bill Bumgarner | Feb 12, 00:46 | |
| Wade Tregaskis | Feb 12, 00:46 | |
| Kyle Sluder | Feb 12, 01:08 | |
| Nick Zitzmann | Feb 12, 01:58 | |
| Jens Alfke | Feb 12, 04:44 | |
| Andrew Farmer | Feb 12, 06:25 | |
| Sean McBride | Feb 12, 16:58 | |
| j o a r | Feb 12, 19:48 | |
| Jens Alfke | Feb 12, 20:14 | |
| Wade Tregaskis | Feb 12, 20:35 | |
| William Squires | Feb 16, 23:35 | |
| Jean-Daniel Dupas | Feb 17, 01:03 | |
| William Squires | Feb 17, 17:59 | |
| glenn andreas | Feb 17, 18:11 | |
| Bill Bumgarner | Feb 17, 18:11 | |
| Jim Correia | Feb 17, 18:13 | |
| William Squires | Feb 17, 18:47 | |
| mmalc crawford | Feb 17, 18:57 | |
| Bill Bumgarner | Feb 17, 19:03 | |
| Jim Correia | Feb 17, 19:04 | |
| William Squires | Feb 17, 19:52 | |
| Jean-Daniel Dupas | Feb 17, 20:18 | |
| Sherm Pendley | Feb 17, 21:03 | |
| Bill Bumgarner | Feb 17, 21:09 | |
| Bill Bumgarner | Feb 17, 21:17 | |
| Jens Alfke | Feb 18, 00:06 |






Cocoa mail archive

