Principles and skills of C ++ Class Library Design

Source: Internet
Author: User

A few days ago, Microsoft launched the Visual Studio Series C ++ class library and the g ++ In the GNU camp's pressure Axis product gc, which greatly excited programmers and developers, for C ++ Class Library Design developers, maintaining the high performance of C ++ is an important goal.

We will describe the simplicity goal at the beginning, and we will discuss it a little more here. The simple standard we proposed is the simple external interface, and the simple internal structure. We know that the class library is provided for upper-layer applications, that is, to provide certain functional services to the upper layer according to certain interface specifications.

The simpler the interface design, the more convenient it is for upper-level users and the less prone to bugs. We can note that the popular successful class libraries all have simple interfaces. In order to make the interface simple, we often have to encapsulate the complexity of the specific implementation in the class library. That is to say, for the design principle of simplicity, the simplicity of the external interface prevails over the simplicity of the internal implementation.

High performance is a feature in C ++ that is superior to other OO languages. The high performance of c ++ should first be attributed to its running mode. Unlike most OO languages, C ++ programs directly generate Native Code on the local platform after compilation ), theoretically, it has the maximum possible execution performance. Another reason is that the mainstream C ++ compilers are well-designed and have superior code optimization capabilities.

  • How to use C ++ for programming
  • Example: C ++ Programming
  • How to Implement Virtual functions in the C ++ virtual function table
  • Dialysis C ++ Class Object Memory Model
  • Static data member in C ++

For C ++ class library designers, maintaining the high performance of C ++ is an important goal. The program's high performance can be evaluated from two aspects: first, time performance, to solve as much business as possible in the shortest time; second, resource performance, to minimize resource consumption, including CPU usage, memory usage, network traffic, and disk space to maintain normal program functions. The main means to improve performance is to optimize the design of the data structure, algorithms and program embodiment structure, 000-861 117-102.

Portability. After C ++ is compiled, the output code is the local platform code. Therefore, C ++ itself does not have the portability of the target code. The portability of C ++ can only be source code portability. Source code Portability means that all or part of the source code of the same software product can be compiled in different compiling environments without compilation ).

In addition, the results have the same quality characteristics, including functionality, reliability, availability, performance, and maintainability ). The compiling environment can be roughly divided into three layers: the operating system at the bottom, that is, the Platform), and the compiler that directly processes the source code, other middleware items required during compilation.

Such as library files. We know that C ++ has achieved unified ISO/IEC in terms of language specifications, but its compiler is a mass cut-off situation. Representative Borland C ++ series have been removed from the market ), the C ++ class library of Microsoft Visual Studio series and the g ++ in the gc of the Pressure Axis product of the GNU camp.

The execution platform for executable code generated after source code is processed by the compiling environment is called the target platform. Different compilers have different target platforms. Some support multiple platforms, such as g ++, some are single platforms, such as Visual C ++. For the class library designer.

It is very difficult to obtain full portability unless it is a class library that is incorporated into the language specification like STL, because STL is not supported, and standard C ++ is not supported. Even though there are different STL implementation versions in different compiling environments, which leads to "multiple implementations of one class library"), we can only selectively support some environments. We have already explained at the beginning that we chose the g ++ and Visual C ++ compilers and the 32-bit Windows and Linux target platforms.

It is very difficult to obtain full portability unless it is a class library that is incorporated into the language specification like STL, because STL is not supported, and standard C ++ is not supported. Even though there are different STL implementation versions in different compiling environments, which leads to "multiple implementations of one class library"), we can only selectively support some environments. We have already explained at the beginning that we chose the g ++ and Visual C ++ compilers and the 32-bit Windows and Linux target platforms.

One solution is to keep the library files in the source code format including header files and source files) without compiling them into binary files. For exampleSTLMany of the implementation versions are in the form of header files. In this way, although it solves the problem of unportable name decoration, it also brings about problems such as code compilation time growth and completely open source code. InC ++Before the name and decoration rules are unified, it seems that this problem is very difficult to solve.

In this series, we also followG ++OfSTLThe implementation method is to compile the class library in the form of header files. Why not put the code in the source file? The main reason is that the header file only requires the use of include commands# Include), And the source file needs to be configured to the compilation target list of the user project, and form a common compilation form with the user's source program, undermining the sealing of the compilation target of the user project, it is troublesome and does not conform to the general habits of software development.

Edit recommendations]

  1. Introduction to C ++
  2. Summary Notes on learning and exploring C ++ library functions
  3. Basic Conception and method of C ++ Class Library Design
  4. Does C ++ really have market value?
  5. Basic Conception and method of C ++ Class Library Design

Related Article

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.