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: Andrew Pinski <email@hidden>
- Date: Fri, 21 May 2004 00:18:07 -0400 (EDT)
>
An NSPoint is defined as a struct like this:
>
>
typedef struct _NSPoint {
>
float x;
>
float y;
>
} NSPoint;
>
>
And when you make the assignment, the code that is called is:
>
>
FOUNDATION_STATIC_INLINE NSPoint NSMakePoint(float x, float y) {
>
NSPoint p;
>
p.x = x;
>
p.y = y;
>
return p;
>
}
>
>
As this is all happening on the stack, just like an int or float etc,
>
there is no extra memory allocation going on - all it does is points to
>
the location of "p" on the stack, and when the frame goes out of scope
>
on the stack all the local variables are popped from the stack.
>
>
So your code is effectively the same as:
>
NSPoint a;
>
NSPoint p;
>
p.x = 10;
>
p.y = 10;
>
a = p;
>
>
I hope this helps make sense of it.
Actually the allocation on the stack was a feature of GCC, this is all
fixed in 3.5.0 which has a new optimization infrastructor which fixes
all of these issues.
So just recompiling with a newer GCC can and will help a lot.
Thanks,
Andrew Pinski
_______________________________________________
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.