View Full Version : NSString or char *

Jan 26, 2011, 11:00 AM
Thanks for the replies, a long gap for this post.

Make me clear on this thread concept as follows :

Suppose I have to store a string "testing app Performance with memory", at the runtime of the code in a class variable.

Then what would be fine to go with :

a) char *stringType="testing app Performance with memory"


b) NSString *stringType=@"testing app Performance with memory"

Which one would be much efficient to go with. AFAIK, going with char* would be memory efficient, as I don't need to use any uincodes for this string.

Note : For now leave the concept of alloc and malloc here.

Jan 26, 2011, 11:14 AM
Assuming you're going to use the string in some Objective-C/Cocoa code at some point (e.g. setting it to a label's text or something), then there is no reason to use anything other than NSString. The memory savings will be negligible and the C string will have to be converted into an NSString before you do anything with it anyway.

The only good reasons I can think of to use C strings are if you are actually using them frequently code that expects C strings, or if you are storing 10's of thousands of them and therefore could actually get a meaningful memory savings from avoiding any NSString overhead.