例如,我在一些 OpenGL 应用程序中有以下绘制函数:
void Terrain::Draw(float ox, float oy, float oz) {
float terrainWidth = stepWidth * (width - 1.0f);
float terrainLength = stepLength * (length - 1.0f);
float startWidth = (terrainWidth / 2.0f) - terrainWidth;
float startLength = (terrainLength / 2.0f) - terrainLength;
(...)
}
Terrain
是一个类,我确信 step 和 terrain 宽度/长度实例变量在对象的生命周期内永远不会改变(它们在第一次调用 draw 函数之前被初始化)。
假设我的应用程序以稳定的 25fps 运行,该函数将每秒调用 25 次。价值观永远不会改变,它们永远是一样的。
将这些函数变量声明为静态变量会有所收获吗?为了防止它们在每次调用函数时被销毁和声明?