Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mpramodjain

macrumors regular
Original poster
Nov 20, 2008
152
0
Banglore
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"

(or)

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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.