Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

dynamic allocation of NSPoints array

30 views
Skip to first unread message

Joe

unread,
Nov 26, 2009, 7:55:34 PM11/26/09
to
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.

Ilya Kulakov

unread,
Nov 27, 2009, 4:45:58 AM11/27/09
to
typedef NSPoint *NSPointArray;

That means an NSPointArray is a pointer to NSPoint structures.
Just follow the rules of allocating dynamic C arrays.

Jason Sikes

unread,
Nov 28, 2009, 3:51:58 AM11/28/09
to

In these situations I often use C++'s vectors. Example:

std::vector<NSPoint> myPointAry;

Vectors in C++ are contiguous
...Fill your array. Then when you need the NSPointArray, cast it
thusly...

[myBezierPath appendBezierPathWithPoints:(NSPointArray) &myPointAry[0]
count:10];

myPointAry[0] of course is the first element of the vector.
&myPointAry[0] is a pointer to the first element of the vector.
Since we know that the rest are contiguous, you have a C array of
NSPoints.
And C++ manages dynamic memory allocation for you. It's quite
efficient.

HTH

0 new messages