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