C + + Performance profiling (iv): Inheritance impact on performance, anatomy inheritance
(This editor has a problem today, all my format is messed up, sorry!) )
Inheritance is an important feature of OOP. Although many peers in the industry do not like inheritance, the correct use of inheritance is an important design decision at the application and architectural levels. How does the use of inheritance, especially in the STD container, affect program performance?
From my personal experience, constructor has a great influence on the creation of class with deep inheritance chains. If the application allows, it is best to use a base class without constructor. Here's an example:
struct __declspec (novtable) ITest1
{virtual void AddRef () = 0;
virtual void Release () = 0;
virtual void DoIt (int x) = 0; };
Class Ctest:public ITest1
{
int ref;
Public:inline CTest () {ref = 0;}
inline void AddRef () {++ref;}
inline void Release () {--ref;}
inline void DoIt (int x) {ref *= x;}
inline void AddRef2 () {++ref;}
inline void Release2 () {--ref;}
inline void DoIt2 (int x) {ref *= x;}
static void Testperf (int loop); };
This is a dummy program, but it is common in COM. If we're going to create and use CTest a lot, experienced programmers should see that ITest1 doesn't need constructor at all. According to the C + + manual, ITest1 because of the virtual function, belonging to the "non-Simple construction Class", the compilation must produce a constructor, its sole purpose is to set the ITest1 vtbl (virtual function table).
However, the only function of interface is to be inherited, so its vtbl must be set by its inheriting class. Compiling in this case does not need to generate constructor. Microsoft was aware of this when designing ATL and launched its own solution to avoid the flaw of the C + + official Spec: VC + + provided the novtable class modifier, telling the compiler: I don't need your constructor. However, my test results in VS 2010 were disappointing:
ITest1 's constructor is still generated, but it does not assign a value to the vtbl , which is a little bit of a drop to improve the performance of the base class structure. Let's look at the effects of this "useless constructor" on performance. We right vote take out another itestpod that doesn't need a virtual function (the pod means "data") to do the comparison:
struct Itest1pod
{inline void AddRef () {}
inline void Release () {}
inline void DoIt (int x) {}};
Itestpod of course not fully used for interface (interface must use virtual functions), just to test. We then design an inheritance class that is exactly the same as the CTest function above:
Class Ctestpod:public Itest1pod
{
int ref;
Public:inline ctestpod () {ref = 0;}
inline void AddRef () {++ref;}
inline void Release () {--ref;}
inline void DoIt (int x) {ref *= x;}
};
Our aim is to use this ctestpod to make a comparison with ctest apples and apples:
void Ctest::testperf (int loop)
{
clock_t begin = Clock ();
for (int i = 0; I < loop; ++i)//LOOP1
{
Ctestpod testpod; Line1
Testpod.addref ();
Testpod.doit (0);
Testpod.release ();
}
clock_t end = Clock ();
printf ("POD time:%f \ n", double (End-begin)/clocks_per_sec);
begin = Clock ();
for (int i = 0; I < loop; ++i)//LOOP2
{
CTest test; Line2
Test. AddRef2 ();
Test. DOIT2 (0);
Test. Release2 ();
}
end = Clock ();
printf ("Interface time:%f \ n", double (End-begin)/clocks_per_sec);
}
The only difference between Loop1 and loop2 above is line1 and line2, in order to avoid the use of virtual functions, I specially prepared ctest for ADDREF2,DOIT2,RELEASE2, three identical but non-virtual functions, To follow a major principle of performance testing: compare Apple to Apple.
I set the loop to 100,000, and the test results showed that the LOOP2 was about 20% lower than the LOOP1 speed. The only difference from the generated code is that the CTest constructor calls the constructor of the compiled auto-generated ITest1. This constructor has no effect, but White takes up a lot of CPU cycles. A good compilation, it should be able to cut off the constructor, this depends on our own to search.
Summarize
When applying inheritance, removing useless constructor from the base class will have a significant effect on the performance of a large number of constructed object. Unfortunately, Microsoft's __declspec (novtable) class modifier did not provide any help to solve the problem. In the application of object design for mass storage, we should try to use Pod as the base class to avoid the obvious performance vulnerability of the above CTest class.
2014-9-3 Seattle
Introduction: The effect of bonding bond between materials on the material ability
In all solids, atoms are bonded together by bonds. The key enables the solid to have strength and corresponding electrical and thermal properties. For example, strong keys result in high melting points, high modulus of elasticity, short atomic spacing, and low coefficient of thermal expansion.
First, the chemical bond
1. Ionic Bond
Ionic bond are caused by the mutual attraction of positive and negative charges. For example, there is an electron in the valence orbit of the sodium atom, which easily releases the outer electrons into positively charged ions. Similarly, the chlorine atom is easy to accept an electron into their valence orbit until it reaches eight electrons and becomes negatively charged ions. Since there is always electrostatic attraction between negatively charged and positive materials, a bond is formed between adjacent ions with different charges. Ionic bond is characterized by positive ions adjacent to the negative ions, and anion adjacent to the positive ions, such as NaCl crystals, see figure 2-1.
2 covalent bonds
Covalent bonds are a strong bond of attraction. When two atoms of the same atom or similar properties are close, the valence electrons do not shift, and the atoms are combined with the force generated by the common electrons to form a covalent bond. Covalent bonds make a strong attraction between atoms, which is evident in diamond, which is the hardest material in nature, and it is composed entirely of carbon atoms. Each carbon atom has four valence electrons, which are shared with neighboring atoms to form a three-dimensional lattice that is completely combined by valence electrons. These three-dimensional lattice makes the diamond has a very high hardness and melting point.
3. Metallic bonding
Metal is a combination of metallic bonding, which has a completely different characteristics from non-metallic. Metal atoms have less electrons in their outer layers and are easily lost. When the metal atoms are close to each other, the outer atoms are separated from the atoms and become free electrons, which are common to the whole metal, and free electrons move in the metal to form electrons. This combination of free electrons and metal cations is called a metal bond, as shown in Figure 2-2. 4. Molecular Bond
Molecular key is also called Van der Waals key, is the weakest bond. It is by the atoms in their respective internal electron distribution uneven generation of weak electrostatic force, called Van der Waals forces, the bond of the molecular force is called the molecular bond.
5. Hydrogen bond
Another kind of Van der Valls is actually a special case of polar molecules. C-h, O-h, or n-h, the proton exposed at the end of the key is not electrically shielded, so the positive charge can attract the valence electrons of neighboring molecules, thus forming a Coulomb-type bond, called hydrogen bond, which is the strongest of all van der Waals bonds. The most typical example of hydrogen bonding is water, a hydrogen proton in a water molecule that attracts the solitary pairs of oxygen in neighboring molecules, and hydrogen bonds make water the highest boiling point in all low-molecular-weight substances.
Effect of bonding bond on material properties
1. Metallic materials
The bonding bond of metal material is the key. Due to the existence of free electrons, when the metal is subjected to an applied electric field, the free electrons in the interior will be directed in the direction of the electric field, forming an electron flow, so that the metal has good electrical conductivity; In addition to the transfer of heat energy by the vibration of the positive ions, the movement of free electrons can also transmit heat, so the thermal conductivity With the increase of the metal temperature, the thermal vibration of the positive ions intensifies, so that the directional movement resistance of the free electrons increases, the resistance increases, so the metal has a positive resistance temperature coefficient; When the two parts of the metal are relatively shifted, the positive ions of the metal still hold the metal bond, so they have good deformation ability; free electrons can absorb the energy Thus the metal is opaque, and the absorbed energy produces radiation when the electrons revert back to the original state, making the metal shiny.
There are also covalent bonds (such as grey Tin) and ionic bond (such as intermetallic compounds mg3sb2) in metals.
2. Ceramic materials
In short, the ceramic material is a compound containing metal and non-metallic elements, the bond bonds are mainly ionic bond and covalent bonds, most of which are ionic bond. Ionic bond gives the ceramic material a fairly high degree of stability, so the ceramic material usually has a very high melting point and hardness, but at the same time the brittleness of the ceramic material is also very large.
3. Polymer materials
The bonding bond of polymer materials is covalent bond, hydrogen bond and molecular bond. wherein, the bonding bond of the constituent molecule is covalent bond and hydrogen bond, and the bond between the molecules is the van der Waals bond. Although the van der Waals key is weak, but the molecular weight of the polymer material is large, so the interaction between the molecules is correspondingly larger, which makes the polymer material has a good mechanical properties.
Third, crystal and non-crystal
After studying the bonding bond, our next task is to think of the material in terms of the arrangement of atoms or molecules ... Remaining full text >>
Three physics of the curtain wall can be experimentally
New specification of glass curtain wall, engineering inspection standard
Discussion and introduction
Shandong Institute of Architectural Sciences (Shandong Province Construction Machinery Quality Supervision and testing center)
Li Chengwei
Shandong Province Construction Machinery Quality Supervision and testing Center as a full-time building curtain wall Inspection Unit, but also as the national Industrial Product production license designated detection units, in recent years, the construction of our province building curtain wall project for a long period of testing and follow-up, initially mastered the construction of our province building curtain wall engineering manufacturing quality and construction level of first-hand information. Compared with the technical level of domestic advanced enterprises, the curtain wall enterprises in our province not only have a certain gap in the production technology level, at the same time, there is a certain distance in the technical design and construction means of the building curtain wall, and the emphasis is reflected in the understanding and implementation of the norms there is a large gap. Below, on the building curtain wall design, calculation and understanding of norms, and so on, talk about our views.
First, "Glass curtain wall Engineering technical Specifications" JGJ102-2003 revised content overview
"Glass curtain wall Engineering technical Specifications" jgj102-2003 since January 1, 2004, the original industry standard "glass curtain wall Engineering technical Specifications" jgj102-96 at the same time abolished. Jgj102-2003 revised content is larger, not only increased the mandatory terms, but also increased the full glass curtain wall and point support curtain wall content, the other content has also been greatly revised.
(i) additional mandatory provisions:
1, silicone structural sealant in the hidden frame and semi-hidden frame glass curtain wall, its glass and aluminum profile bonding must use medium-sized silicone structural sealant.
Silicone structural sealant Before use, should be approved by the state testing institutions and its contact material compatibility and peel adhesion test, and to meet the shore hardness, the standard state of tensile adhesion performance for re-inspection. Inspection of unqualified products shall not be used. Imported silicone structural sealant should have a commodity inspection report. Silicone structural sealants and silicone construction sealants must be used within the validity period.
The structure of silicone sealant should be based on the different stress conditions to carry out the limit state of the bearing capacity checking.
In addition to the full glass curtain wall, should not be injected in the field silicone structural sealant.
2, structural parts should be in accordance with the provisions of the load bearing capacity and deflection and meet the requirements of the norms.
Pillars of the main parts of the section of the aluminum profile openings should not be less than 3.0mm thickness, the thickness of the closed parts should not be less than 2.5mm, the profile hole wall and screw directly between the threaded force connection, its local thickness should not be less than the nominal diameter of the screw; Steel profile section of the main force should not be less than 3.0mm thickness.
The thickness of the aluminum alloy profile of the main force section of the beam should not be less than 2.0mm; when the cross beam span is greater than 1.2 m, the thickness of the main force parts of the beams should not be less than 2.5mm. The local section thickness should not be less than the nominal diameter of the screw when the thread is connected with the screw directly between the hole wall and the bolt. The thickness of the main parts of steel section should not be less than 2.5mm.
3, the staff flow density, youth or young children activities in public places and the use of vulnerable areas, its glass curtain wall should be used safety glass, the use of vulnerable areas, should be set up a clear warning signs.
(b) The main content of all glass curtain wall:
Panel glass thickness should not be less than 10mm, when the panel glass is laminated, its monolithic thickness should not be less than 8 mm.
The section thickness of glass ribs should not be less than 12mm, and the section height should not be less than 100mm. Moreover, the article is a mandatory clause.
Under the action of the standard value of wind load, the deflection limit value of glass rib should be 1/200 of its calculation span.
The curtain wall glass with floating-head connector should not be less than 6 mm, and the curtain wall glass with countersunk head connector should not be less than 8 mm thickness. The gap between the glass width should not be less than ten mm, and should be used in silicone building sealant stitching. This section is a mandatory clause.
The supporting structure of the point supporting glass curtain wall should be calculated separately.
No matter the single steel or steel pipe as a supporting structure, the use of truss or hollow truss as a supporting structure, under the action of wind load standard value, its deflection limit is appropriate to take its span of 1/250.
Tension bar cable system should be in the positive and negative two directions to form a stable structure to withstand wind load or earthquake action, connecting parts, compression rods or tie rods should be used stainless steel material, the diameter of the member should not be less than 10mm, cable steel wire diameter should not be less than 8 mm. Rod should not be used for welding, cable should not be used welding. Under the action of the standard value of wind load, its deflection limit should take its span ... Remaining full text >>
http://www.bkjia.com/PHPjc/873922.html www.bkjia.com true http://www.bkjia.com/PHPjc/873922.html techarticle C + + performance profiling (iv): The impact of inheritance on performance, analysis of inheritance (this editor is defective today, my format is all messed up, sorry!) Inheritance is one of the OOP ...