In Java, I would pass bytes around as byte[] which also knows it's own length. is there an equivalent array in Objective C?
I'm not sure, but NSArray seems too heavy weight for something like that as it can hold any type.
In Java, I would pass bytes around as byte[] which also knows it's own length. is there an equivalent array in Objective C?
I'm not sure, but NSArray seems too heavy weight for something like that as it can hold any type.
I think the closest thing is NSMutableData
and its mutableBytes
property. That'll give you a C style array with a length count attached. The only slight complexity is that while you can read and modify entries by mutableBytes, you need to use appendBytes:length:
to add extra bytes onto the end should you want the buffer to grow.
I think Tommy has the correct answer, but it's worth noting that you can also use the primitive C data types (i.e., char*
in this case). When things get very low level -- as might be the case when you're talking about individual bytes -- avoiding some of the cleverer stuff may perform better.
I also think @Tommy has the correct answer, but it's also worth considering that the built in storage classes are heavily optimized. Unless you are confident that performance will be an issue, it may be easier to use NSMutableArray and only move away after you've shown that you're having performance issues. If you need to store primitive values, take a look at CFMutableArray.