Rahul Vyas
Rahul Vyas

Reputation: 28720

Does #defines decrease performance?

I would like to know that if we #define a particular function like this

#define POST_NOTIFICATION(NAME, OBJECT) [[NSNotificationCenter defaultCenter] postNotificationName:NAME object:OBJECT]

will using above decrease performance?

Upvotes: 0

Views: 60

Answers (2)

Szymon Rozga
Szymon Rozga

Reputation: 18168

No. #define is a preprocessor directive meaning that anywhere the preprocessor sees the POST_NOTIFICATION symbol, it will replace it with the [[NSNotificationCenter ...]] code.

Upvotes: 1

Moszi
Moszi

Reputation: 3236

No, it won't decrease performance. The #define directives are preprocessor directives, which are "replaced" in code before compiling, so the final binary code is the same. However you should refrain from using defines ... It might seem to make the code more readable, however it does not really do it ... Also for one-lines like in the example you gave the benefit probably is not that high to use it.

However to answer your question, the final binary is not different if you use this construct, so there is no performance decrease.

Upvotes: 0

Related Questions