• 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: Stupid objective-c question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stupid objective-c question


  • Subject: Re: Stupid objective-c question
  • From: Britt Durbrow <email@hidden>
  • Date: Mon, 26 Sep 2016 02:45:48 -0700

>
> 	void *kMyContext = &kMyContext;
>
> is *guaranteed* to give you a unique address that nobody else's object may occupy?
>

Splitting hairs, but that’s not ***guaranteed*** - just super highly unlikely to have a collision.

There’s never any guarantee that somebody else isn’t Doing It Wrong (TM).

Some yahoo sticking something like this in their framework or plugin could well create havoc, should you get unlucky…

void *thisWillNeverCollideWithAnything = 0x000000010003b568LL; // Yeah, right! And I gotta bridge to sell you!



________________________________________________________________________



Also, FWIW, even declaring a single pointer variable in the global space that isn’t used as an actual variable strikes me as a bit of a code smell…. perhaps this is something that there should be a compiler extension for… something like this, maybe:

NS_UNIQUE_TOKEN(myContext);

which would resolve to:

static const void *myContext __attribute__((uniqueToken));

and that attribute would cause the pointer to be given a unique address by the linker (i.e, no hazard of coalescing), without the physical RAM actually being allocated for it (or, alternatively, perhaps all unique tokens could just be lumped together in a separate page, so that if the OS is doing lazy RAM allocation, that page - because it should never be de-referenced - never gets physically allocated).

or Swiftly,

uniqueToken myContext; // no ‘let’ here because I think it would be unnecessary and awkward; as there is no initializer half to the statement.

:-)
_______________________________________________

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


  • Follow-Ups:
    • Re: Stupid objective-c question
      • From: Quincey Morris <email@hidden>
References: 
 >Stupid objective-c question (From: Gabriel Zachmann <email@hidden>)
 >Re: Stupid objective-c question (From: Graham Cox <email@hidden>)
 >Re: Stupid objective-c question (From: Quincey Morris <email@hidden>)
 >Re: Stupid objective-c question (From: Graham Cox <email@hidden>)
 >Re: Stupid objective-c question (From: Doug Hill <email@hidden>)
 >Re: Stupid objective-c question (From: Jens Alfke <email@hidden>)
 >Re: Stupid objective-c question (From: Gabriel Zachmann <email@hidden>)
 >Re: Stupid objective-c question (From: Quincey Morris <email@hidden>)
 >Re: Stupid objective-c question (From: Sandor Szatmari <email@hidden>)
 >Re: Stupid objective-c question (From: Uli Kusterer <email@hidden>)

  • Prev by Date: SecStaticCodeCheckValidity fails when app is lauched from Terminal
  • Next by Date: Re: SecStaticCodeCheckValidity fails when app is lauched from Terminal
  • Previous by thread: Re: Stupid objective-c question
  • Next by thread: Re: Stupid objective-c question
  • Index(es):
    • Date
    • Thread