Whitch way is faster?
is this faster in runtime?:
class myclass
{
void POOP()
{
//STUFF
}
};
or this?:
class myclass
{
void POOP();
};
myclass:OOP()
{
//STUFF
}
The first...by a few microseconds. The first way inlines it. That means that whenever the compiler comes across a call to the function, it will replace that call with the code that''s in the function. In the second way it jumps to the function. Inline it if you call it many times a frame, but otherwise it will just increase your exe size.
Actually, putting the function body in the class definition does not necessarily mean that the function will actually be inlined. The normal inlining requirements apply, e.g. no recursion, should be a short function, can't have a pointer taken to it, etc.
According to most C++ programmers you'd ask, the BETTER way to do it (when possible) is the second, because it allows you to separate interface from implementation. Changing stuff like this simply to wring a few more cycles out of your engine is a really bad idea. It's called "micro-optimzation". It's also called "premature optimization".
"Sneftel is correct, if rather vulgar." --Flarelocke
[edited by - sneftel on November 7, 2003 1:51:31 PM]
According to most C++ programmers you'd ask, the BETTER way to do it (when possible) is the second, because it allows you to separate interface from implementation. Changing stuff like this simply to wring a few more cycles out of your engine is a really bad idea. It's called "micro-optimzation". It's also called "premature optimization".
"Sneftel is correct, if rather vulgar." --Flarelocke
[edited by - sneftel on November 7, 2003 1:51:31 PM]
quote:Original post by Sneftel
According to most C++ programmers you''d ask, the BETTER way to do it (when possible) is the second, because it allows you to separate interface from implementation. Changing stuff like this simply to wring a few more cycles out of your engine is a really bad idea. It''s called "micro-optimzation". It''s also called "premature optimization".
Being a C++ programmer, that is correct, but if you still want the inline effect, you can use the inline keyword on the function in the class to have it still tell the compiler you want it to be inline;
quote:Original post by Newfound Ajarn
Being a C++ programmer, that is correct, but if you still want the inline effect, you can use the inline keyword on the function in the class to have it still tell the compiler you want it to be inline;
Most compilers ignore the inline keyword, except for forbidding you from taking a pointer to the function. It''s sort of like the
register
keyword. "Sneftel is correct, if rather vulgar." --Flarelocke
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement