2014年10月29日 星期三

NSMutableArray initWithCapacity 的用途

對於Mutable的物件,init不會配置足夠的記憶體,隨著內容物件的增加而重新配置記憶體,這會造成效能上的損失,為了解決這個問題,我們可以使用這個方法,在初始化時就先指定之後會用到的記憶體大小給你的Array,但不用擔心overflow因為如果使用超過了,仍然會幫你增加。
Returns an array, initialized with enough memory to initially hold a given number of objects.

Return Value

An array initialized with enough memory to hold numItems objects. The returned object might be different than the original receiver.

Discussion

Mutable arrays expand as needed; numItems simply establishes the object’s initial capacity.
This method is a designated initializer.

沒有留言:

張貼留言