Variables, constants, small integers pool and garbage collection

1 variable

1.1 What is a variable?

Status records of a transaction amount / feature. The amount of change is the amount may vary.

1.2 composition variables

( 1 ) variable name: the description of the variable. 
( 2 ) the assignment symbol '= ': a bond from the variable name and value. 
( 3 ) values.
Compositional variables

1.3 naming variables

( 1 ) variable only by numbers, underscores and English letters. 
( 2 ) variable can not start with a number. 
( 3 ) variables can not use keywords. 
Note: Variables do not try to start with an underscore begin with an underscore have a special meaning. 
        The default variables in lower case letters and underlined combination. 
        js default hump body, constant default all uppercase.
        
Naming variables
Named variables generally see the name EENOW
note

1.4 Variable attributes

( 1 ) the above mentioned id: arguably the memory address of a variable. 
( 2 ) type: the type of the variable (commonly used seven kinds, namely: int , a float ., STR, List, dict, and tuple SET)
( . 3 ) value: value.
Attribute variables
1 the same value as the variable, id values are not necessarily the same. (Python optimized since memory pool mechanism i.e. small integers, such that within a small range of integers pool, when the value of the same variable, the same as the id value)
 the same id value 2, the value of the variable be the same.
note

 

 

 

2 Constant

2.1 What is a constant?

Constant is the same amount.
python is not constant, all uppercase general default is constant. This is different js, js is constant. 
If no one else is allowed, generally do not modify the constants others. If you write, try not to modify.
note

 

3 small integer pool 

3.1 The reasons arising

1 small integer is an integer frequently used by
 2 if there are multiple bindings for the same variable name value, the computer will open up a memory address for each value, this caused great waste of resources. In order to save space and improve resource utilization of space resources, python optimize the memory mechanisms, those frequently used integer assigned in advance a good memory address. If more than one variable name to bind those values, we do not need to open up new additional memory space. This is a small integer pool.
View Code

3.2 range

-5~256

4 garbage collection

Garbage collection comes with a python.
1 reference count: if the variable name and value have a binding relationship, his reference count counts as 1, if there are n counts as n. 
Each increase or a decrease, increase or decrease the reference count is one, when the reference count is 0, the system automatically recover its resources. 
2 marks clear: When the memory overflows or is about to reach a threshold, the system will block all programs, those labeled reference count of zero, batch cleared.
3 generational Recovery: Recovery is a sub-generation space for time mode of operation, Python memory is divided into different sets according to the survival time of the object, each set known as a surrogate, Python memory into a 3 "generation" , respectively, for the young generation (generation 0), the year (1st generation), year old (second generation), their position is three lists, they increase the survival time of garbage collection and reducing the frequency of the object small. 
The newly created objects are allocated in the young generation, the total number of the young generation of the list reaches the upper limit, Python garbage collection mechanism will be triggered, those objects can be recycled recycling out, and those objects are not recovered will be moved in years to go, and so on, the old era of an object is the longest survival time of the object, or even survive in the life cycle of the system. 
At the same time, generational recovery is built on clear labeling technology base. Generational recycling the same treatment as the auxiliary container object that garbage collection techniques of Python
   
View Code

 

Guess you like

Origin www.cnblogs.com/cmd61/p/11115965.html