compiler optimization - C++ inline methods with same if statements -


I am writing handler for OpenGL texture and I'm thinking about security and performance. Which level of adaptation should be marked?

  struct Texture2D {GLuint ID; Inline texture 2D (): ID (0) {}; Inline Clear Texture 2D (GluIt ID): ID (id) {}; ~ Texture2D (); Zero genotypes (bull regeneration = falls); Zero removal (); Zero commitment (); Zero Parameter (GLNM PNN, GL Floyd Ultimate); Zero parameter (GLenum pname, GLint param); Zero glTexParameterfv (GLenum target, GLANM PNA, const GLflot * parameter); Zero GlTexParameteriv (GLenum Goal, GLANM Pinnam, Const GLIT * Parameters); Constant texture 2D dam; }; Inline Zero Texture2D :: Genature (Bull Regedon) {if (ID) {if (regen) DeleteTtexture (); Other Returns; } Glendatur (1, and ID); } Inline Zero Texture2D :: DeleteTexture () {glDeleteTextures (1, and ID); Id = 0; } Inline Zero Texture Texture 2D :: Bindectations () {glBindTexture (GL_TEXTURE_2D, ID); Binded.ID = ID; } Inline Zero Texture2D :: parameter (GLenum pname, GLfloat param) {if (binded.ID == ID) // This BindTexture (); // This glTexParameterf (GL_TEXTURE_2D, Pinnam, Ultimate); } Inline zero texture2D :: parameter (GLenum pname, GLint param) {if (binded.ID == ID) // This BindTexture (); // This glTexParameterf (GL_TEXTURE_2D, Pinnam, Ultimate); } Inline Texture 2D :: ~ Texture 2D () {Deleted pieces (); } // This load load loads (...) {Texture2D t; T.GenTexture (); T.BindTexture (); // if the statements t in the next tasks. Parameter (...); T.Parameterf (...); T.Parameterf (...); T.Parameterf (...); T.Parameterf (...); }  

none

There is a story of sadness, but C ++ assumes that if you call a function, then this function can produce all kinds of side effects including changing the value of the tied id I

except

If you make sure that the functions you make are in your < If there is no legal way to know about code> bindend.ID , then directly By By Drbhit) or indirectly (because someone else has a hint of it, and it is passed). This is a simple example (assuming that side_effect () is in a separate translation unit)

  int side_effect (); Int k = 1; Int main () {side_effect (); If (k = 0) 0; Side effects(); If (k = 0) 0; Side effects(); If (k = 0) 0; }  

can use side_effect () and change it by legally declaring it as an external form. No call from side_effect can be adapted away.

  int side_effect (); Static Int k = 1; Int main () {side_effect (); If (k = 0) 0; Side effects(); If (k = 0) 0; Side effects(); If (k = 0) 0; }  

side_effect is not possible to access k in a valid way, because you use the position in another translation Can not unit. Therefore code can be customized side_effect (); Return 0 because Kashmir will not change, unless the background- which of course will be undefined behavior.

  int side_effect (); Zero snatch (int *); Static Int k = 1; Int main () {snach (& amp; amp; k); // !!! Side effects(); If (k = 0) 0; Side effects(); If (k = 0) 0; Side effects(); If (k = 0) 0; }  

There is no way to know the compiler, if snitch () saves its logic in the place where side_effect () Can change, therefore, call can not be made to side_effect () .

If you have k as a local variable, then you can get the same position: If there is a possibility that some unknown routine k can be used in a legal way, then can not optimize based on the value of the compiler.

PS: Creating k const does not help, as it is legal to remove a const constance as the optimization signal Can not be used.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -