BSS segment, data segment, code segment, stack, pointer/reference

Source: Internet
Author: User

BSS segments: In a segmented memory management architecture, BSS segments (BSS segments) are generally a memory area used to store uninitialized global variables in the program. BSS is short for block started by symbol. BSS segments belong to static memory allocation.

Data Segment: In a segmented memory management architecture, data segments (data segments) are generally a memory area used to store initialized global variables in the program. The data segment belongs to the static memory allocation.

Code segment: In the framework of segmented memory management, the code segment (code segment/text)
Segment) generally refers to a memory area used to store Program Execution Code. The size of this area is determined before the program runs, and the memory area is usually read-only,
Some architectures also allow code segments to be writable, that is, self-modified programs are allowed. In the code segment, it may also contain some read-only constant variables, such as string constants.



Stack, also known as stack, is a special data structure in the form of a linked list in Computer Science. Its special feature is that it can only be at one end of the linked list (called the stack top, (top. In addition, the implementation of the stack data structure can also be completed through arrays.

Strictly speaking, heap refers to a piece of memory that is at the control of programmers when the program is running.
Stack stack refers to the memory zone in which parameters are transmitted when a function is called.

Since the stack data structure only allows operations at one end, it works according to the principle of LIFO-last in first out.

The stack data structure supports two basic operations: Push and POP ):

1. Stack pressure (in stack): pushes an object or data to the stack, updates the top pointer of the stack, and points it to the object or data that finally enters the stack.
2. Stack play (Out stack): return the object or data pointed to at the top of the stack, delete the object or data from the stack, and update the top of the stack.

Differences between references and pointers in C ++
When the pointer is initialized, it can point to an address or be empty. ---- The reference must be initialized as another variable.

 

The pointer in C/C ++ is actually a variable, which is similar to other types of variables. It is a variable that occupies four bytes (on a 32-bit machine ), its difference from other variables lies in its
The variable value is a memory address that points to another place in the memory. Reference is an alias, which is similar to alias in Linux. Furthermore, I
A pointer variable can point to null, indicating that it does not point to any variable address, but the reference must be bound to an existing variable at the time of declaration.
It cannot be changed.

 

If it is to pass a pointer, copy the pointer first and use the copied pointer inside the function. This Pointer Points to the same address as the original pointer, if the copied Pointer Points to another new object within the function, the original pointer will not be affected;
However
If the passed pointer points to a new object, the original pointer points to a new object, which causes memory leakage, because the pointer can no longer be pointed
Reference. Even if the passed pointer is not directed to a new object, but the pointer is released at the end of the function, the original pointer cannot be used outside the function, because the original memory has been released
.

 

References and pointers

★Similarities:
1. All are addresses;
The Pointer Points to a piece of memory, whose content refers to the address of the memory, and the reference is the alias of a piece of memory.

★Differences:
1. the pointer is an entity, and the reference is only an alias;
2. You do not need to unreference (*) when using a reference. The pointer must be unreferenced;
3. The reference can only be initialized once during definition, and will not be changed afterwards; the pointer will be variable;
Reference "from one end" ^_^
4. The reference has no const, the pointer has const, And the pointer of const is immutable;
5. The reference cannot be blank, and the pointer can be blank;
6. "sizeof reference" gets the size of the variable (object) to which it points, while "sizeof Pointer" gets the size of the pointer itself (the address of the variable or object to which it points;
Typeid (t) = typeid (T &) always true, sizeof (t) = sizeof (T &) always true,
However, when a reference is a member, the occupied space is the same as that of the pointer (the standard rule is not found ).
7. the pointer and reference auto-increment (++) operations have different meanings;

★Contact
1. Reference is implemented using pointers inside the language (how to implement it ?).
2. For general applications, the reference is understood as a pointer and no serious semantic error is made. A reference is a pointer with limited operations (only content operations are allowed ).

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.