将对象设置为NULL和使用ZeroMemory之间究竟有什么区别?
我听说在WinAPI(主要是C)中,一个人应该在C对象上使用ZeroMemory是一种很好的做法.我来自C#的背景,这似乎是一个C++人真正应该知道的东西.
我发现使用DirectX API,无论你是否ZeroMemory对象,应用程序仍然有效,但有些示例使用ZeroMemory,有些则没有.
任何人都可以澄清这些事情吗?
这是微优化,还是优化呢?
void Renderer::SetCamera(FLOAT x, FLOAT y, FLOAT z) {
// Checking for zero before doing addition?
if (x != 0) camX += x;
if (y != 0) camY += y;
if (z != 0) camZ += z;
// Checking if any of the three variables are not zero, and performing the code below.
if (x != 0 | y != 0 | z != 0) {
D3DXMatrixTranslation(&w, camX, camY, camZ);
}
}
Run Code Online (Sandbox Code Playgroud)
使用带有vector.size()的条件运行for循环会强制应用程序重新计算每个循环中向量中的元素吗?
std::vector<UINT> vect;
INT vectorSize = vect.size();
for …Run Code Online (Sandbox Code Playgroud)