FROM : Bruce Truax
DATE : Fri Dec 10 17:05:18 2004
I am still struggling with the retain/release concept. I hope someday to
fully understand it. Most of the time I end up with the correct pairing
because I poke around and look at the retain count and because most times it
does not make much difference. I now have a case where I want to create a 2
dimensional NSArray from a C array of floats and I have upwards of 200,000
elements in the array so I don't want to have a lot of improperly retained
variables. Below I have included the source code to the function which
creates the array. Could someone provide me with the proper retain/release
protocol? Should I set up an autorelease pool for this function?
When I call the function I the calling statement is:
[self setDisplayArray:[self buildArrayFromCArray:outputArray
ofSize:numberOfPoints
withXDimension:xSize
withYDimensiont:ySize]];
When I call this setter function and the display array is released I want to
make sure that all of the row arrays are also released.
- (NSMutableArray *)buildArrayFromCArray:(float*)input
ofSize:(int)nPoints
withXDimension:(int)xDimension
withYDimensiont:(int) yDimension
{
NSMutableArray *theArray;
int column=0;
int row=0;
int i=0;
theArray = [[NSMutableArray alloc] initWithCapacity:xDimension];
for (column = 0; column<xDimension; column++){
NSMutableArray *rowArray = [[NSMutableArray
alloc]initWithCapacity:yDimension];
for (row = 0;row<yDimension; row++){
NSNumber *point = [[NSNumber alloc] initWithFloat:input[i]];
[rowArray addObject:point];
i++;
}
[theArray addObject:rowArray];
}
return theArray;
}
Thanks.
Bruce
DATE : Fri Dec 10 17:05:18 2004
I am still struggling with the retain/release concept. I hope someday to
fully understand it. Most of the time I end up with the correct pairing
because I poke around and look at the retain count and because most times it
does not make much difference. I now have a case where I want to create a 2
dimensional NSArray from a C array of floats and I have upwards of 200,000
elements in the array so I don't want to have a lot of improperly retained
variables. Below I have included the source code to the function which
creates the array. Could someone provide me with the proper retain/release
protocol? Should I set up an autorelease pool for this function?
When I call the function I the calling statement is:
[self setDisplayArray:[self buildArrayFromCArray:outputArray
ofSize:numberOfPoints
withXDimension:xSize
withYDimensiont:ySize]];
When I call this setter function and the display array is released I want to
make sure that all of the row arrays are also released.
- (NSMutableArray *)buildArrayFromCArray:(float*)input
ofSize:(int)nPoints
withXDimension:(int)xDimension
withYDimensiont:(int) yDimension
{
NSMutableArray *theArray;
int column=0;
int row=0;
int i=0;
theArray = [[NSMutableArray alloc] initWithCapacity:xDimension];
for (column = 0; column<xDimension; column++){
NSMutableArray *rowArray = [[NSMutableArray
alloc]initWithCapacity:yDimension];
for (row = 0;row<yDimension; row++){
NSNumber *point = [[NSNumber alloc] initWithFloat:input[i]];
[rowArray addObject:point];
i++;
}
[theArray addObject:rowArray];
}
return theArray;
}
Thanks.
Bruce
| Related mails | Author | Date |
|---|---|---|
| Bruce Truax | Dec 10, 17:05 | |
| Will Mason | Dec 10, 20:15 | |
| Jeff Gilbert | Dec 10, 21:01 | |
| Bob Ippolito | Dec 10, 21:07 | |
| Ricky Sharp | Dec 11, 00:56 |






Cocoa mail archive

