iOS tagged pointer detailed

Source: Internet
Author: User
Tags integer

Objective

In September 2013, Apple launched the iphone5s, while IPhone5S equipped with the first 64-bit architecture of the A7 dual-core processor, in order to save memory and improve execution efficiency, Apple proposed the concept of tagged pointer. For 64-bit programs, the introduction of tagged pointer, the relevant logic can reduce the memory footprint by half, and 3 times times the speed of access, 100 times times the creation, destruction speed. This paper starts with the problem that tagged pointer tries to solve, leads the reader to understand the details and advantages of tagged pointer, and finally points out the precautions in use.

Problem

Let's take a look at why the original object wastes memory. Suppose we want to store a NSNumber object whose value is an integer. Normally, if this integer is just a Nsinteger variable, then it occupies the memory is related to the CPU number of bits, 32-bit CPU 4 bytes, under 64-bit CPU is 8 bytes. The size of the pointer type is usually related to the number of CPU bits, one pointer occupies 4 bytes under 32-bit CPU, and 8 bytes under 64-bit CPU.

So an ordinary iOS program, if there is no tagged pointer object, from 32-bit machine to 64-bit machine, although the logic does not change any, but this kind of nsnumber, nsdate objects such as the memory will be doubled. As shown in the following illustration:

Let's look at the problem of efficiency, in order to store and access a NSNumber object, we need to allocate memory for it on the heap, in addition to maintain its reference count, manage its lifetime. These add additional logic to the program, resulting in a loss of operational efficiency.

Related Article

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.