Understanding of PHP stack data segment code segment

Hits: 0

Understanding of PHP stack data segment code segment

Stack: basic data type (roughly understood as space A, where the number 8 is stored)
Heap: object created by new
Code segment: function, running code
Number segment: string constant, global variable, static variable, etc.

Objects in PHP are the same as integers and floating-point types. They are also data classes. They are used to store different types of data and are loaded into memory for use at runtime.

Logically speaking, memory is roughly divided into 4 segments, stack space segment, heap space segment, code segment, initialization static segment, and different declarations in the program are placed in different memory segments.

The data segment usually refers to the global variables that have been initialized and are not 0 in the program, such as static variables and constants.

Code segment (code segment / text segment) usually refers to a memory area used to store program execution code, such as functions && methods

The stack space segment is a place to store data types that occupy the same space length and occupy a small space, such as integers, etc., the space occupied in the memory is the same length, and they are 64 bits and 4 bytes.

Then the length of the data is not fixed, and the data type with a large space for comrades is placed in the heap memory.

Stack memory can be accessed directly, while heap memory is memory that cannot be accessed directly. For the program, the object is like a large data type, and the type that takes up space is of variable length, so it will be placed in the heap.

But the object name is placed on the stack, so that the object can be used by the name of the object.

For example $p = new Persion, $p is the name of the object we instantiate, and the same is true

$p1,$p2It is also the name of the object from the instance. Each object has its own independent space, which is not connected and does not affect each other.

$p = new Person

The right side of the equal sign is the object instance, the entity in the heap memory, the left side of the equal sign $pis a reference variable, the address of the object is assigned to the reference variable $p through the assignment operator =, so $p is the variable that stores the address of the object, $p is placed in the stack memory, $p is equivalent to a pointer to the object in the heap, so we operate the object through the $p reference variable, which can usually be called an object reference as an object

You may also like...

Leave a Reply

Your email address will not be published.