Re: alloc ... initWith ... malloc and NSObject
Re: alloc ... initWith ... malloc and NSObject
- Subject: Re: alloc ... initWith ... malloc and NSObject
- From: Andy Lee <email@hidden>
- Date: Sat, 11 Jun 2005 22:43:49 -0400
On Jun 11, 2005, at 10:27 PM, Prachi Gauriar wrote:
On Jun 11, 2005, at 9:52 PM, email@hidden wrote:
Now the problem is how do I create an array of MyPolygon
objects without using NSMutableArray but perhaps using malloc
and yet still manage to call the initWithVertexCount method?
So you mean a C array? Then you would do it just like you do in C:
MyPolygon **polygons = malloc(polygonCount * sizeof(MyPolygon *));
int i;
for (i = 0; i < polygonCount; i++) {
polygons[i] = [[MyPolygon alloc] initWithVertexCount:vertexCount];
}
And to avoid memory leaks, release memory accordingly in your -
dealloc method:
for (i = 0; i < polygonCount; i++) {
[polygons[i] release];
}
free(polygons);
--Andy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden