Allocating memory (stack or heap) is not a good idea in a tight loop. This is because allocation is anyway a little costly (specially heap allocation).
In your method, you can ditch the error
variable and insert the function right into the if
condition so that you wont allocate extra variables:
if (getParameterAPI(objectHandle, parameterName, ¶meterA) != 0)
{
throw std::runtime_error("Cannot get parameterA.");
}
Other than that, your implementation doesn't take up much performance (depends on the driver, how you communicate between them and the logic behind getParameterAPI
itself).
Note: If you take data into getParameterAPI()
by reference (const
or not), that might improve performance slightly, as you don't have copying in it (especially when it comes to memory). But still, it only affects if your arguments are quite large.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…