Do a NSInteger occupies memory? Should we use it in a FOR loop?
-
Also note that if you have a loop with an integer inside, the integer's scope is the loop. Upon next loop, a new integer will be used and the old one gets out of scope. So no matter how often you loop, you occupy 4 bytes.Krumelur– Krumelur2011-02-23 20:35:02 +00:00Commented Feb 23, 2011 at 20:35
Add a comment
|
2 Answers
Look at the Apple documentation, a NSInteger is this :
#if __LP64__ || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
typedef long NSInteger;
#else
typedef int NSInteger;
#endif
It's just 4 bytes on an iPhone, just like an int, you don't have to worry about memory.
Comments
NSInteger is just an alias for the native integer type. Cmd+Dbl Click on it and see.
1) It uses stack memory (I assume) while it is in scope and releases it when it goes out of scope.
2) Yes, use it in a for loop.