Several principles of functions and function parameters of C++ performance series

Several principles of C++

  • Unless parameters are used to pass data to the caller, parameters are generally marked with const
  • The return value type of the function generally adds the const flag, and the function return value of the pointer type generally does not add the read-only identifier of the pointer itself.
  • In principle, function value types do not return pointer types, but only structures and common basic data types.
  • The principle of memory management is whoever applies and who maintains and who releases, and the principle of pointer passing who needs to copy, and the caller does not reserve the memory pointed to by the pointer for the called function.
  • The return value of the function generally does not return the object of the complex data structure, but passes the pointer of the complex data structure object through the parameter. In the same way, the called function does not request memory for the object to the caller.
  • The essence of cloning is to obtain the value of the private member without changing the permissions of the private member. Member functions are shared. Its scope varies depending on the object on which it is invoked.
  • The address space of a member function is global, and anyone can get its entry through address retrieval. The problem that cannot be called directly lies in its scope. The local variable accessed by the member function is not the memory it applies for. Different objects call the same member function to process the member variable of the same name, and the processed variables are different.
  • The ideal model for cloning is that the abstraction layer manages the list of objects that implement the clone at the implementation layer and still does not need to know the concrete type that implements the clone method.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326671803&siteId=291194637