Re: dynamic NSPointArray allocation
Re: dynamic NSPointArray allocation
- Subject: Re: dynamic NSPointArray allocation
- From: Jonathan Dann <email@hidden>
- Date: Tue, 1 Dec 2009 14:27:57 +0100
Just use NSPointerArray:
@implementation NSPointerFunctions (Additions)
static NSUInteger _PointerFunctionsCGPointStructSize(const void *item)
{
return sizeof(CGPoint);
}
+ (NSPointerFunctions *)pointerFunctionsForCGPoint;
{
NSPointerFunctions *aPointerFunctions = [NSPointerFunctions pointerFunctionsWithOptions:(NSPointerFunctionsStructPersonality|NSPointerFunctionsMallocMemory|NSPointerFunctionsCopyIn)];
[aPointerFunctions setSizeFunction:&_PointerFunctionsCGPointStructSize];
return aPointerFunctions;
}
@end
@implementation NSPointerArray (Additions)
+ (id)pointPointerArray;
{
return [[[self alloc] initWithPointerFunctions:[NSPointerFunctions pointerFunctionsForCGPoint]] autorelease];
}
- (CGPoint)pointAtIndex:(NSUInteger)theIndex;
{
return *(CGPoint *)[self pointerAtIndex:theIndex];
}
- (void)addPoint:(CGPoint)thePoint;
{
[self addPointer:&thePoint];
}
@end
Jonathan
http://madebysofa.com
On 27 Nov 2009, at 21: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.
> _______________________________________________
>
> 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
_______________________________________________
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