Summary of C + + knowledge points (updated from time to times)

Source: Internet
Author: User

"Object-oriented concept"

All things in the world have attributes and methods, which are encapsulated as an object, object-oriented programming thought summed up its characteristics are encapsulation, inheritance, polymorphism, etc., the class instance is an object, the data member in the class, the member function is the object's property and operation, the instance relation and the inheritance relation is the static relation between the objects, While message passing is the dynamic relationship between objects, multi-state realizes the reaction action of the object, object-oriented and process-oriented, mutually complements, object-oriented can solve more complicated problems, the object-oriented programming idea can be applied to the design of large-scale software design system.

"Memory allocation"

Stack Area:
The parameters of the stored function, local variables, the return address of the program, and so on, the compiler will automatically allocate memory when needed, and will be automatically cleared when it is not needed.
Heap Area:
Assigned and released by the programmer, if the programmer does not release, the operating system will be released at the end of the program, distributed in a similar way to the list, the dynamic allocation of memory is here, New,malloc, need to use Delete,free to release.
Static or global zone:
Static variables and global variables are placed here, the system is released after the program finishes, initialized static variables and global variables are placed in one piece, uninitialized in another adjacent area.
literal constant Area:
Constant string, const type does not allow modification
Program code Area:
Binary code that holds the body of the function
Reference: http://blog.csdn.net/hairetz/article/details/4141043

"The difference between heaps and stacks"

1. From a spatial distribution perspective
Under Windows, the stack is the data structure to the low address extension, is a contiguous area of memory, the top of the stack address and the maximum capacity of the stack is the system pre-defined, can be obtained from the stack of small space, traverse is from the high address to the low address, the operating system automatically assigned and released, stored function parameter value, local variable value , its operation is similar to the stack in the data structure;

A heap is a data structure that extends to a high address and is a discontinuous area of memory. This is due to the fact that the system uses a linked list to store the free memory address, which is naturally discontinuous, while the traversal direction of the list is from the low address to the high address. The size of the heap is limited by the valid virtual memory in the computer system. Thus, the heap to obtain more flexible space, also relatively large, by the programmer allocated to release, if the programmer does not release, the program at the end of the operating system may release the recovery, New,malloc application of the dynamic space is stored here.

2. Data structure Differences
Stack: advanced data structure;
Heap: A completely binary tree, divided into large top piles and small top piles

3. How the cache differs
The stack uses a first-level cache, which is usually placed in storage space and released immediately after the call is completed;
The heap is stored in a level two cache, and the life cycle is determined by the garbage collection algorithm of the virtual machine.

"Virtual function/pure virtual function"

A function declared in a base class vitual a virtual function that the derived class can redefine, which is also a virtual function in a derived class, and the Vitual keyword can be omitted in a derived class. To implement polymorphism, the meaning of pure virtual functions is that the function provides an interface that can be overridden for descendant types, but the version in this class is never called, and the class cannot create objects, and the class exists only for other classes to inherit.

"Polymorphic"

Polymorphism refers to the different actions that occur when the same object receives different messages or when different objects receive the same message, only for references or pointers to the types that are associated by inheritance, and in C + +, which is defined as virtual functions, the base class expects derived classes to redefine the implementation polymorphism.

"Const Usage"

The const modifier acts as a protective function, declaring a variable, a pointer, a function parameter return value, and so on, which is modified to be immutable.

"C + + allocates and frees memory differences"

C:
The Malloc/free,calloc,realloc are all functions
Pointer name = (data type *) malloc (memory size to request sizeof (type))
Pointer name = (data type *) calloc (n, type size sizeof), allocates n contiguous memory of size.
Pointer name = (data type *) realloc (to change the memory size of the pointer name, the new size)

C++:
New/delete as operator

malloc and free are standard library functions for c++/c languages, and new/delete are operators of C + +. They can all be used to request dynamic memory and free memory. For non-intrinsic data type objects, light Malloc/free cannot satisfy the requirements of dynamic objects. Objects are automatically executed when they are created, and the object executes the destructor automatically before it dies. Because
Malloc/free is a library function, not an operator, not within the control of the compiler, and is not able to impose the task of executing constructors and destructors on Malloc/free.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Summary of C + + knowledge points (updated from time to times)

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.