NSArray的大小和可变性 [英] NSArray size and mutability

查看:256
本文介绍了NSArray的大小和可变性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,我通常初始化是一个特定的大小,然后添加和更换对象作为我的code推移阵列。在Objective C,我不能这样做,有一个NSArray。我已经从Java移植往往超过code的使用NSMutableArray里,我以为比NSArray中表现较差efficent。 (我最好的猜测,如何存储的NSMutableArray它的成员是用链表,但我可能是错的)

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)

有没有有固定的尺寸和允许阵列内的任何变化对各类目标C数组?为什么不能在与NSArray的某个对象来代替对象?我可以用C数组做到这一点,为什么不目标C?

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?

推荐答案

您的假设是错误的,的NSMutableArray 将不会有任何比一个普通 NSArray的。

Your assumption is wrong, NSMutableArray won't be any slower than a plain NSArray.

的NSMutableArray 不打算使用一个链表,它会使用动态数组。这是每一位快,除了在需要的地方调整插入一个普通的数组。但是,由于这些指数得到进一步分开,其摊销到几乎相同,和相同的,如果你不打调整大小。

NSMutableArray is 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.

这是基本相同的Java的的ArrayList

It's basically the same as Java's ArrayList.

这篇关于NSArray的大小和可变性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆