Re: Accessor method for array of floats
Re: Accessor method for array of floats
- Subject: Re: Accessor method for array of floats
- From: Johan Kool <email@hidden>
- Date: Sat, 19 Jul 2003 23:28:00 +0200
Thanks Dylan and Jim for your replies.
The type of array I was looking for to store in my accessor is a plain
C array of floats.
If I understand you and this matter correctly, this is what I need to
put in my model:
-(void)setArrayOfFloats:(float)inArray withCount:(int)intValue {
numberOfPoints = intValue;
arrayOfFloats = realloc([intValue*sizeof(float));
arrayOfFloats = inArray;
}
-(float)arrayOfFloats {
return arrayOfFloats;
}
-(int)numberOfPoints {
return numberOfPoints;
}
and in the init of this model:
arrayOfFloats = malloc(1*sizeof(float)) // just so I can use realloc()
all the other times
Then when I want to store the data in my models accessors I call:
[myModel setArrayOfFloats:myArray withCount:count];
and to get it back I call:
float *localArray;
localArray = malloc([myModel numberOfPoints]*sizeof(float))
localArray = [myModel arrayOfFloats];
NSLog(@"LocalArray value at index 0: %e", localArray[0]);
I do indeed want my entire array back and not asking for it from my
model for each value separately, as I need to do quite some
calculations on it and localArray[n] is much easier to use and read
then [[myModel arrayOfFloats] objectAtIndex:n]; is. I likely need all
values anyway.
Thanks for the sample code for the NSMutableArray and NSTableView as
well, I needed some help on that too, how did you know!? ;-)
Johan
PS All typed in Mail (I don't have access to PB right now) so there
might be some typos here.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.