• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Zeroing out instance variables
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Zeroing out instance variables


  • Subject: Re: Zeroing out instance variables
  • From: Michael Ash <email@hidden>
  • Date: Sun, 18 Apr 2010 23:13:39 -0400

On Sun, Apr 18, 2010 at 10:58 PM, Kyle Sluder <email@hidden> wrote:
> On Apr 18, 2010, at 6:52 PM, Michael Ash <email@hidden> wrote:
>
>> If by "indirected through the runtime" you mean "accesses one global
>> variable to get an offset". It does not, as one might take your
>> comment to indicate, actually call any runtime functions.
>
> If that's the case, how can the language support reordering instance
> variables? The only way I can see o support taking the address of an
> instance variable is to convert &ivar into a runtime call.

Why not take a look for yourself?

$ cat ivartest.m
#import <Cocoa/Cocoa.h>
@interface Foo : NSObject { id ivar; } @end
@implementation Foo
- (void)testMethod {
    ivar = nil;
}
@end
$ gcc -c ivartest.m
$ otool -tV ivartest.o
ivartest.o:
(__TEXT,__text) section
-[Foo testMethod]:
0000000000000000	pushq	%rbp
0000000000000001	movq	%rsp,%rbp
0000000000000004	movq	%rdi,0xf8(%rbp)
0000000000000008	movq	%rsi,0xf0(%rbp)
000000000000000c	movq	0xf8(%rbp),%rdx
0000000000000010	movq	_OBJC_IVAR_$_Foo.ivar(%rip),%rax
0000000000000017	movq	(%rax),%rax
000000000000001a	leaq	(%rdx,%rax),%rax
000000000000001e	movq	$-[Foo testMethod],(%rax)
0000000000000025	leave
0000000000000026	ret

As you can see, the offset of the ivar itself is referenced as a
linker symbol which will then get resolved at load time. And you can
see that no function calls take place.

Mike
_______________________________________________

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

References: 
 >Zeroing out instance variables (From: Ben Haller <email@hidden>)
 >Re: Zeroing out instance variables (From: Ken Thomases <email@hidden>)
 >Re: Zeroing out instance variables (From: Ben Haller <email@hidden>)
 >Re: Zeroing out instance variables (From: Charles Srstka <email@hidden>)
 >Re: Zeroing out instance variables (From: Kyle Sluder <email@hidden>)
 >Re: Zeroing out instance variables (From: Ben Haller <email@hidden>)
 >Re: Zeroing out instance variables (From: Kyle Sluder <email@hidden>)
 >Re: Zeroing out instance variables (From: Michael Ash <email@hidden>)
 >Re: Zeroing out instance variables (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: Blend mode 'darken' for NSImage?
  • Next by Date: Re: Blend mode 'darken' for NSImage?
  • Previous by thread: Re: Zeroing out instance variables
  • Next by thread: Re: Zeroing out instance variables
  • Index(es):
    • Date
    • Thread