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: Gideon King <email@hidden>
- Date: Fri, 21 May 2004 13:35:08 +1000
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.
Gideon King
NovaMind Software
Mind Mapping for MacOS X
<
http://www.nova-mind.com>
On 21/05/2004, at 12:17 PM, Christoffer Lerno wrote:
>
Having programmed java almost exclusively for many years now, memory
>
allocation questions in obj-c sometimes leave me a little confused.
>
>
If I use NSMakePoint in this manner:
>
>
NSPoint a=NSMakePoint(10,10);
>
>
Am I not:
>
>
a) first creating an empty, static bound, NSPoint.
>
b) then allocate memory and create yet another NSPoint with the
>
NSMakePoint command.
>
>
The static NSPoint will disappear when it runs out of scope, but what
>
about the point created with NSMakePoint, isn't that one dynamically
>
created and as such needs to be explicitly deallocated? I don't really
>
see any code actually deallocating these kinds of structs though, so
>
I'm suspecting I don't need to, but if so - why?
>
>
>
/C
>
_______________________________________________
>
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.
_______________________________________________
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.