Checking if a pointer is NULL like this, is this fast? If it is done every frame, many times….
e.i.
void SomeFunction(MyClass* myClass)
{
//Check to see if the pointer is NULL. If so, do nothing
//Is this fast enough to do often or is heavy on performance?
if(myClass == NULL)
return;
//If not NULL, do something
myClass->DoSomeOtherFunction();
}
also, is there a difference between the top one these other two ways to do it? Which one of the three is best?
I bet this code will be compliled in the same assembler instructions. Pointer is usually fit to integer size, and most CPUs have very quick check for zero integer value.
In short: all of your code should be fine. That’s not the thing you should worry about.
are faster if the compiler don’t optimize the code of
void SomeFunction(MyClass* myClass)
{
//Check to see if the pointer is NULL. If so, do nothing
//Is this fast enough to do often or is heavy on performance?
if(myClass == NULL)
return;
//If not NULL, do something
myClass->DoSomeOtherFunction();
}