In c, if I wanted an array of floats (for instance) I would just define the fixed size and allocate it, and I could access each element for math operations. However, I want the ability to have my arrays be mutable since they will continually grow in size (as the app is running, and the array could easily surpass 10000+ elements) and the idea of NSMutableArray sounds great. However, (if I understand correctly) it only stores objects, I would have to wrap my numbers in NSNumber, and then put those into the array. That seems like a ridiculous amount of overhead to just store an array of floats (or doubles or integers).
On the other hand, I see that there are flout attributes for Core Data, but I don’t see how I could access this in the same way ( array[index] ). Am I missing something here? Should all heavy-lifting math just be done in fixed-sized c arrays, are there ways of using the foundation classes that I haven’t stumbled upon, or are there ways of accessing core data objects like one would access an array?
you aren’t missing anything here; there’s not a formal objc interface for arrays of c scalar types.
the simple way (as westsider mentioned) is to use
std::vector, and then implement serialization/deserialization using a mechanism such as CF/NS-Data.you could wrap std::vector in an objc interface, if you wanted:
then, you’d have accomplished objc serialization without hassle.
there’s also a way to use a CF/NS_MutableArray for scalars, using pointer (or narrower) sized entries:
however, that would still fail to properly deserialize itself without customization. so… NSPointerArray would accomplish that more easily… but you still fixed to pointer sized values, so you have to write it yourself. which not terribly hard. the downside is the number of variants you may ultimately end up with.