Creation and maintenance of Python integer object Pyintobject

Source: Internet
Author: User

There are several ways to create an integer object, not the 3 types described in this book

From the source to see the end is called Pyint_fromlong, the book written in the Pyint_fromfloat, need to pay attention to this.

So the key reading function Pyint_fromlong:

User-friendly access, small integer object pool is a python run must exist. According to this idea, then the small integer object pool initialization should be in the Pyintobject _init, in the source code also confirms this idea:

The small_ints array manages pointers to small integer objects. In the Pyint_fromlong function, the small numeric object is taken out of the array.

A large integer object does not use an object pool, it is directly allocated a block of memory for its use. Manage several pyintobject in block

From the source can be known, this block about 1K size. The pointers free_list and block_list represent the header and footer of the single-linked list, respectively. The basic operation of a single-linked list is the list operation in C language. is not detailed.

In Pyint_fromlong, you can see that the block used to create a large integer object is a function of fill_free_list

It was really amazing to see the array turned into a linked list here. This does, however, improve the use of memory for idle integer objects.

Summary: The creation and use of integer objects in Python 2.5 is more frequent, and in order to improve efficiency, shared memory is used to cache common integers.

Code modification Test

As amended in the original book:

After recompilation:

The results of the analysis are consistent with those described in the book. Then it is suggested to return to the first chapter, to understand more deeply the Python built data object

Creation and maintenance of Python integer object Pyintobject

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.