Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

define Vs static constant Vs NSString -- Memory point of view

What is the best bet between:

#define kYes @"Yes"

AND

static NSString *const kYes = @"Yes";

And

NSString *kYes = @"Yes";

from memory consumption point of view. Keeping in mind that there will be thousands of constants in the application.

like image 979
Abhinav Avatar asked Mar 30 '11 08:03

Abhinav


1 Answers

From the memory stand point - static variable is better, since it's referenced once. The #define will insert the string into all the occurrences, by that - multiplying the memory usage... (that is unless GCC optimizing same constant string occurrences, which it actually might. in that case - there is no difference)

like image 147
reflog Avatar answered Oct 20 '22 00:10

reflog