Re: dynamic NSPointArray allocation
Re: dynamic NSPointArray allocation
- Subject: Re: dynamic NSPointArray allocation
- From: Quincey Morris <email@hidden>
- Date: Fri, 27 Nov 2009 13:19:20 -0800
On Nov 27, 2009, at 12:46, Shane wrote:
> I don't know how large my NSPointArray size needs to be so I'd like to
> know how I would dynamically allocate NSPoints to populate an
> NSPointArray? I think I can do it with NSMutableArray, but
> NSBezierPath takes an NSPointArray (which is what my end result is for
> the points) and it just seems cleaner and more efficient if I can stay
> with that instead of converting between point arrays and mutable
> arrays.
The most direct (and C-ish) way is to malloc memory for the NSPointArray and realloc it whenever you need to grow its size.
The easiest way (and Objective-C-ish way) is to use a NSMutableData object with the NSPointArray as its data. Whenever you want to add points, just resize the NSMutableData object to 'sizeof (NSPoint)' * total number of points, and use '(NSPointArray) [data mutableBytes]' as a pointer to the start of the array.
(If you use the latter approach, and you're using garbage collection, and you assign the '[data mutableBytes]' pointer to a stack variable or pass it as a method parameter, make sure you keep the NSMutableData object reference alive until you're done with the 'mutableBytes' pointer.)
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden