Next: NSArrays are immutable Up: NSArray Previous: What is it

Comparison with Pure C Arrays

In a GNUstep tool or application, you can use pure C arrays as well, exactly as you do in C. NSArrays have some advantages and disadvantages over pure C arrays. The first advantage is that the programmer interface of NSArray is slightly easier, which makes your code simpler to read, maintain and debug. In particular, if you use arrays which can be modified (NSMutableArrays), the GNUstep library shrinks or expands the array automatically for you as needed when you add or remove objects, without you having to manually allocate or resize the memory needed for the array. The second advantage of NSArrays is that they provide facilities to do things which are not necessarily straightforward to do with pure C arrays. In the last section of this tutorial we will be learning about one of this facilities, the ability of saving an array of strings (and other simple objects) into a plain text file, and automatically recreating the array by reading the information from the file. The main disadvantage is that a NSArray is slower than a pure C array, but you should not overestimate this problem, which becomes important only when you need really fast code and have to iterate over really big arrays. In most cases, using a C array or a NSArray does not make any real difference on the performance; but of course there are cases in which it does.


Next: NSArrays are immutable Up: NSArray Previous: What is it
Nicola 2002-01-13