• 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: 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.


References: 
 >Re: NSMakePoint and such - what about memory allocation? (From: Gideon King <email@hidden>)

  • Prev by Date: Re: Cocoa Bindings - many people using them?
  • Next by Date: Re: [firstPath appendBezierPath: [secondPath bezierPathByReversingPath]];
  • 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