C++ language foundation, language features, data structure, operating system knowledge and even some kernel related knowledge, network related knowledge, database operation, multi-thread multi-process data synchronization mutually exclusive, memory related knowledge and so on.
1. What is the difference between MALloc in C and NEW in C++
Malloc differs from new in the following ways: (1) new and delete are operators that can be overloaded and can only be used in C++.
(2) Malloc and free are functions that can be overridden in C and C++.
(3) New can call the constructor of the object, and the corresponding DELETE calls the corresponding destructor. (4) Malloc only allocates memory, free only reclaims memory, does not perform construction and destructor
(5) New and delete return a pointer to a data type, while malloc and free return a void pointer. Note: the malloc memory should be free, and the new memory should be delete.
Because they work differently.
2.. When a program should use threads and when a single thread is efficient.
1 Time-consuming operations use threads to improve application responsiveness
2 In parallel operation, threads are used, for example, concurrent threads on the server side of THE C/S architecture respond to user requests.
3 In a multi-CPU system, using threads improves CPU utilization
4. Improve the program structure. A long and complex process can be considered divided into several threads, separate or semi-independent running parts, so that the program is easier to understand and modify. All other cases use single threads.
3. Why should we encapsulate related topics? What is polymorphism and how is it implemented? The application scenario of polymorphism? Is the virtual function table a class or a member? What about virtual Pointers? Virtual function, pure virtual function? When to use virtual functions and when to use pure virtual functions? Have virtual function why still use pure virtual function, can replace pure virtual function with virtual function? Can the constructor of a class be defined as virtual? What about the destructor? Why do destructors of base classes usually need to be virtual? What’s the problem if you don’t define it as virtual? When does this happen? What are the parameters required when defining copy constructors? Why are parameters defined as references, and what are the problems if they are not? What is deep copy? How to implement deep copy? What are the use scenarios for constructor member initializer lists? When must I use the initializer list?
C and C++ memory allocation?
1 Allocated from a static storage area. Memory is allocated when the program is compiled. The memory is allocated for the entire run of the program, such as global variables, static variables.
2 Create it on the stack. During the execution of a function, storage units for local variables within the function can be created on the stack and released automatically at the end of the function execution. Stack memory allocation operations are built into the processor’s instruction set, which is highly efficient, but the allocated memory capacity is limited.
3 Allocation from the heap (dynamic memory allocation) When a program is running, it allocates any amount of memory with malloc or new. The programmer is responsible for when to free the memory with free or DELETE. Dynamic memory lives on its own and is very flexible to use.