objective c - Preferred approach with int values while adding 64-bit support to iOS app -
i updating old ios app not support 64-bit architectures.
from apple's conversion procedure, looks converts "int , unsigned int nsinteger , nsuinteger, respectively." however, when doing this, end lot of casting longs during formatting, shown below. concerned performance on 32-bit architectures because of of casting long.
//old nsinteger myintvalue = 5; [nsstring stringwithformat:@"%d", myintvalue]; //new nsinteger myintvalue = 5; [nsstring stringwithformat:@"%ld", (long)myintvalue];
an alternative replace usages of nsinteger int, remain 4-byte values, not need cast long when formatting myintvalue.
//old nsinteger myintvalue = 5; [nsstring stringwithformat:@"%d", myintvalue]; //new int myintvalue = 5; [nsstring stringwithformat:@"%d", myintvalue];
should latter method avoided particular reason, assuming items change nsinteger int guaranteed fit inside 4-byte int?
those castings only way format strings when compiling both 32- and 64-bit alternative worse (in opinion):
#if __lp64__ [nsstring stringwithformat:@"%ld", myintvalue]; #else [nsstring stringwithformat:@"%d", myintvalue]; #endif
there no significant performance issues worry cast it's matter of how space made on stack , maybe sign-extension. minor stuff.
Comments
Post a Comment