I have a ccarray and I thought that I always had to know the initial size....
So I do this: CCArray initwith开发者_如何学Gocapacity 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?
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 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.
精彩评论