Reputation: 138
I'm getting familiar with objC, but I'm still confused as to when using C is the better option.
I have a number that changes periodically, and I'd like to get it's average of the last 10 values. I'm thinking the best way to do it is to create and array of a defined size of 10. Every time it changes, it gets added to that array, and the last value gets popped off, so its an array of the 10 freshest values.
I think I can handle the averaging part, so what I'm asking is:
Is there a type of array/vector/struct that automatically handles popping/pushing if it has a defined size? Is it NSMutableArray using +arrayWithCapacity, or is there a better/faster way using a C array like number[10]?
Upvotes: 1
Views: 603
Reputation: 4454
I think you are looking for a Queue or a First In Last Out Mechanism, Please look at
Objective-C equivalent of Java's BlockingQueue?
Upvotes: 2