How can apps on iOS be compatible with 32-bit and 64-bit systems?
When Apple launched the iPhone 5S, the 64-bit application came to the fore. At that time, I saw Apple's official materials announcing that the iOS7.x SDK supports 64-bit applications, and the built-in applications are already 64-bit.
I remember that I had a 16-bit system when I first got in touch with my computer, and the pointer's addressing range was still 16-bit. When TurboC was used in the current year, we also needed to select the tiny mode or other based on the application size. Later, I used a 32-bit model for programming for a long time. 4G is a boundary condition that is firmly remembered. Now, 64-bit is coming.
Just like 16-bit to 32-bit, the hardware must be the first to be launched, and the SDK will be followed up. Then, various third-party applications will be followed up gradually. This process usually takes some time. After Apple launched the app this time, it was also in a 32-bit and 64-bit parallel transition period for a long time. However, as Apple announced in August, from January 1, all apps uploaded to the AppStore must support ARM64, click here for details.
So I started to look at how 32-bit applications are converted to 64-bit applications.
1. Basic Knowledge
Xcode 5.0.1 starts to support compiling 32-bit and 64-bit Binary files.
Both 32-bit and 64-bit are supported. We need to select the minimum deployment target as iOS 5.1.1.
64-bit Binary must run on a 64-bit CPU, and the minimum OS version is 7.0.3.
2. Basic Steps for application compatibility with 64-bit
Install Xcode5.0.1 or later -- in fact, at least 5.1.1 is required for Xcode versions that can be submitted to AppStore now.
Open the project, compile, correct errors and warnings in Xcode, especially for 32-bit and 64-bit
In Project Setting, change the SDK used by the Minimum application to version 5.1.1 or later.
Set the ubuntures parameter to "Standard ubuntures (including 64-bit )."
In this way, your application supports 64-bit CPU, and the compiler errors and warnings are fixed again. Please note that the compiler has no warning for some problems.
Test your application on a 64-bit real machine
Use Instruments to view memory usage
3. Changes from 32-bit to 64-bit
3.1 Data Type changes
Here, the number of bytes occupied by the language's built-in types and the differences in the byte alignment. In the 32-bit era, the IPL32 specification was used. After 64-bit, the LP64 specification was changed.
In addition, there are also floating point types. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + icagicagpgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20141114/2014111409055028.png" alt = "\">
In the data type, NSInteger is equivalent to int in 32-Bit mode and long in 64-Bit mode. This data structure is widely used and will be directly replaced with int in many nonstandard scenarios, there is no problem in 32 bits, but in 64 bits, This is a hidden danger. CGFloat has the same problem, so you must check and modify the code carefully.
As for alignment, if the offset is used to access the struct items, You need to carefully check the items. The rest is good. Of course, if you use malloc, check the allocated memory size. We recommend that you use sizeof for computation.
In addition, for stored files, such as files stored on iCloud, you cannot determine whether a 32-bit application or a 64-bit application will access these files, the data content must be interpreted exactly.
3.2 changes in method calls
64-bit applications require all functions to have the original type, which is a good coding habit.
The shape of the function must be exactly the same as that of the prototype. In particular, the function pointer shape with an uncertain number of parameters must be avoided (printf type)
When a 64-bit system is running, calling a function is different from a 32-bit system. The main difference is that when passing parameters of a function with a variable number of parameters, let's look at the following code:
int fixedFunction(int a, int b);int variadicFunction(int a, ...); int main{ int value2 = fixedFunction(5,5); int value1 = variadicFunction(5,5);}
The first function is fixed to pass in two parameters. The second function has an indefinite number of parameters. in use, two parameters are also input. In 32-bit systems, the parameter transfer of these two functions is very similar, and in 64-bit systems, the two are completely different.
3.3 differences in assembly
Because it is a different instruction set, assembly will certainly be different. However, our general applications do not use assembly, so this is rarely encountered.
4. Third-party Libraries
Finally, the third-party libraries used in our project must support 64-bit systems. Otherwise, they are useless. Therefore, during the upgrade, you need to check the third-party library you are using to see if a 64-bit version has appeared.
In Apple's current system (iOS7/iOS8), 32-bit frameworks and 64-bit frameworks coexist, so if all applications are 64-bit, the system automatically does not load the 32-bit framework, which can occupy less resources. In addition, it is good for running speed. That is to say, you will feel that the mobile phone is running faster.
After the application is compatible with 64-bit systems, the memory usage will definitely increase, but the performance will also be improved accordingly.