In Java, I commonly initialize arrays that are a specific size and then add and replace objects as my code goes on. In Objective C, I can’t do that with an NSArray. Code that I have ported over from Java often has to use NSMutableArray, which I assume perform less efficent than NSArray. (My best guess as to how NSMutableArray stores it’s members is using a linked list, but I could be wrong)
Are there any types of arrays for Objective C that have fixed sizes and allow changes within the array? Why is it not possible to replace objects at a certain object with NSArray? I can do this with C arrays, why not Objective C?
Your assumption is wrong,
NSMutableArraywon’t be any slower than a plainNSArray.NSMutableArrayis not going to use a linked list, it will use a dynamic array. It is every bit as fast as a plain array except on the insertions where it needs to resize. But since those get exponentially further apart, it amortizes to nearly the same, and identical if you don’t hit a resize.It’s basically the same as Java’s
ArrayList.