Re: NSMakePoint and such - what about memory allocation?
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.