• 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: NSMakePoint and such - what about memory allocation?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMakePoint and such - what about memory allocation?


  • Subject: Re: NSMakePoint and such - what about memory allocation?
  • From: Wade Tregaskis <email@hidden>
  • Date: Fri, 21 May 2004 13:22:37 +1000

The source to NSMakePoint probably looks something akin to:

static inline NSPoint NSMakePoint(double x, double y) {
NSPoint temp = {x, y};

return temp;
}

When any degree of optimisation is engaged, the compiler is intelligent enough* to dissolve the temporary storage and assign directly to the function return space in the stack. In fact, once the inlining occurs this is just like writing manually:

myPoint.x = x;
myPoint.y = y;

So the function will be as efficient as physically possible, at least for "Deployment" builds (i.e. -O2).

FWIW, this seems to stem from the fact that you don't get any sort of implicit constructor for structs, i.e. you can't embed NSPoint(x, y) in your code... this has annoyed me on hundreds of occasions; I can't even begin to imagine what the creators of C were thinking when they overlooked this.**

Wade Tregaskis (aim: wadetregaskis)
-- Sed quis custodiet ipsos custodes?

* = Standard disclaimer: gcc seems to have quite poor output in some cases, so I'm talking hypothetically to a degree
** = Yes, I'm aware you can write manual constructors, but it should be implicit.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >NSMakePoint and such - what about memory allocation? (From: Christoffer Lerno <email@hidden>)

  • Prev by Date: Re: NSMakePoint and such - what about memory allocation?
  • Next by Date: build styles override target settings (was: does not execute on launch)
  • Previous by thread: Re: NSMakePoint and such - what about memory allocation?
  • Next by thread: Re: NSMakePoint and such - what about memory allocation?
  • Index(es):
    • Date
    • Thread