简体   繁体   中英

CCArray initwithcapacity and resizing

I have a ccarray and I thought that I always had to know the initial size....

So I do this: CCArray initwithcapacity 4

However I accidentally added 5 items to the array and the program did not crash. Does CCArray automatically resize or am I going to run into memory issues later?

The term "capacity" with regard to data structures usually (as in this case) means a "hint" as to the size of the array, not its actual size. When created with capacity 4, the array is empty, not of size 4, and you will be able to add as many elements as you like without memory issues.

You need to give an initial capacity (as you gien 4) after that if you add more element in CCArray it expend at runtime.

it's act same as NSMutableArray .

Mutable arrays expand as needed; capacity number simply establishes the object's initial capacity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM