How apps on iOS are compatible with 32-bit systems and 64-bit systems

Source: Internet
Author: User

When Apple launched the IPhone5S, 64-bit apps came to the front. At that time, I saw Apple's official profile announcing that Ios7.x's SDK supports 64-bit applications, and that the built-in apps are already 64-bit.

I remember I had a 16-bit system when I was in touch with the computer, and the pointer was 16-bit addressable. When using TURBOC, the choice is tiny mode or other depending on the size of the application. After a long time using 32-bit model programming, 4 G is a boundary condition that is firmly remembered. And now, 64 people have come to the front.

Just as the 16-bit to 32-bit, the hardware is definitely the first launch, the SDK will follow up, and then a variety of third-party applications will be gradually followed up, this process generally need to continue for some time. This time after the introduction of Apple, a long time in the 32-bit and 64-bit parallel transition period, but, with the October Apple announced, February 1, 2015, upload appstore application will need to support ARM64, specific information please poke here.

So I started looking at how 32-bit apps turn into 64-bit apps

1. Basic knowledge

Xcode 5.0.1 started supporting the compilation of binary 32-bit and 64-bit

While supporting 32-bit and 64-bit, we need to select the minimum deployment target for IOS 5.1.1

64-bit binary must be running on a CPU that supports 64-bit, and the minimum OS version requirement is 7.0.3

2. Basic steps to make your app compatible with 64-bit

Install Xcode5.0.1 or later--in fact, you can now submit AppStore version of the Xcode is at least 5.1.1

Open engineering, compile, fix errors and warnings in Xcode, especially for 32-bit and 64

In Project setting, change the SDK used by the smallest application to 5.1.1 or later

Set the architectures parameter to "standard architectures (including 64-bit)."

This allows your app to support 64-bit CPUs, fix compiler errors and warnings again, and be aware that some issues with the compiler are not warning

Test your app on a 64-bit real-world machine

Use instruments to view the status of memory usage


3. Changes from 32-bit to 64-bit

3.1 Changes in data types

This is mainly the number of bytes in the language built-in type and the difference in byte alignment. In the 32-bit era, the IPL32 specification was used, and after 64 bits, it was changed to the LP64 specification.

In addition to these, there are floating-point types

In the data type, Nsinteger is equivalent to int at 32 bits, which is equivalent to long when 64 bits, and this data structure is used very widely, many nonstandard times will be used directly and int, in 32 bit is no problem, but in 64 bit, this is the hidden danger. CGFloat also has the same problem, so the code must be carefully checked for changes.

As for alignment, if you use an offset to access the struct's items, you need to check carefully, the rest is good, of course, if you use malloc, then please check the allocated memory size, it is recommended to use sizeof to help calculate.

Also, for stored files, such as files stored on icloud, you can't be sure whether a 32-bit app or 64-bit app will be accessed, then be sure to write the interpretation of the data content exactly the same.


3.2 Changes on the method call

64-bit applications require that all functions have prototypes, which in itself is a good coding habit

The shape of the function must be exactly the same as the prototype, especially to avoid the undefined number of function pointer shapes (printf Class)

In a 64-bit system, calling functions at run time and 32-bit systems is different. The main difference is that when passing parameters of a function with a variable number of arguments, 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 a fixed pass in 2 parameters, the second function is a variable number of arguments, in use, also passed 2 parameters. In a 32-bit system, the parameter passing of these two functions is very similar, and in the 64-bit system, the two are very different.


3.3 Different of the compilations

Because it is a different set of instructions, the compilation will of course be different. However, our general application does not use the assembly, so this one is relatively rare.


4. Third-party libraries

Finally, the third-party libraries used in our project will definitely need to support 64-bit systems, otherwise it will be useless. So everyone in the upgrade need to check their own use of the third-party library, to see if there is already a 64-bit version appeared.


Apple's current system (IOS7/IOS8), the 32-bit framework and the 64-bit framework coexist, so if all applications are 64-bit, the system automatically does not load the 32-bit framework, which can be less resource-intensive, In addition to the speed of operation is good, that is to say, you will feel the phone running a little faster.

After the application is compatible with 64-bit systems, the memory footprint will certainly be a bit more, but the performance will be improved accordingly.


How apps on iOS are compatible with 32-bit systems and 64-bit systems

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.