Embedded C ++-Efficiency Analysis on C ++ (top Embedded Open Source)

Source: Internet
Author: User

C ++
It brings us object-oriented support, which has been often used in large-scale embedded projects in recent years. Even some newer operating systems, such as eCos and Symbian, are all written in C ++. However, C ++ has introduced many expensive features while bringing convenience. WithEmbedded


Development Application
C ++
As a development language, there are more and more companies and projects, many of which originally work in the desktop Development Field
C ++
The programmer has joinedEmbedded


Development camp. For these transfers from desktop DevelopmentEmbedded


Under development
C ++
In terms of development, special attention should be paid to program efficiency and resource usage to understand what
C ++
Features may cause costly execution time and code size, and avoid using them if possible.

 

  • Class and Object


C ++
Class to facilitate object encapsulation.Embedded


It is fully usable during development.
C
Language
Struct
Compared to the class, there is almost no larger overhead. A list of Public and Private member data and functions
Struct
And the list of function prototypes are not significantly different.
C ++
The compiler can use
Public
And
Private
The keyword determines which method call and data access are allowed or not, but this decision is completed during compilation, so the runtime will not pay the price. Simply adding a class will not affect the code size, nor affect the efficiency of your program, but also facilitate object encapsulation.

 

  •  
    Default parameters and function Overloading

Mo
The parameter value is also not lost. The compiler only adds code so that a default value is passed every time a function is called without parameters. Similarly, the function name overload is modified during compilation. With the same name
A function with different parameters is assigned a unique name during compilation. Each time the function name appears in the program, the compiler replaces it, And the connector matches them correctly. Almost none of these
The only drawback is that symbol tables are slightly more complex. The overload of operators is similar to this, and there is almost no runtime overhead.

  • Constructor, constructor, and virtual function


Structure
Creating functions and destructor may cause some loss. These special methods ensure that each time an object of this type is called when it is created or exceeds the scope. However, this small amount of overhead is paid to reduce errors
A reasonable price is acceptable. Similarly, virtual functions have a reasonable cost-benefit ratio. The obvious cost is that a storage query is attached before a virtual function is called, while common functions and methods
The call is not affected. It is acceptable because it is the basis for implementing polymorphism and has a low cost.

  • Expensive features

Based on average experience, it is relatively expensive
C ++
Features:Template, exception event, and operation type identification
. These three features have a negative impact on the code size, and exception events and runtime type recognition will increase the execution time. Before deciding whether to use these features, you may want to experiment to see how they affect the size and speed of your own applications.

 

 

In factEmbedded


For software
C ++
Whether it is worth the performance loss has always been controversial. In
1996
A group of Japanese chip manufacturers joined up to define
C ++
A subset of languages and libraries to make it more suitableEmbedded


Software development. They call their new industrial standardsEmbedded



C ++
. As
C ++
Appropriate subset of the draft standard,Embedded



C ++
Omitted many things that can be omitted without limiting the expressiveness of lower-layer languages. These omitted features not only include expensive features such as multi-inheritance, virtual base class, runtime type recognition, and exception handling, but also include some of the latest addition features, such: template, empty name question, new type conversion, etc. All that is left is
C ++
Is still object-oriented and
C
Is a superset, but it has significantly less runtime overhead and smaller Runtime Library. PairEmbedded



C ++
If you are interested, please refer to the following link:
Embedded C ++
Detailed definition (
Specification
):
Http://www.caravan.net/ec2plus/spec.html

.

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.