Hi,
I'm currently 'implementing' correct usage of const function parameters and class member functions.
During this I'm running into the following:
- class 'MyClass' has several (unsigned) int variables, which are used throughout the member functions for for loops, counter etc.
- when I try to make one of these member functions 'const', which is logical looking at the functions itself, but this doesn't work, since the used counter variables are members of the class
The solution seems very simple, create local (unsigned) int variables for my loops within the member functions.
My question:
- would it be a bad idea, memory/ performance wise, to do this?
For example, my rendermesh and rendersubmesh functions have one or more for loops, using a class member for the for loop.
This would mean I 'make' a new integer in the local functions, for each submesh/ mesh I render in every frame.
Any input is really appreciated.
Example:
void CD3dmesh::RenderMesh(LPDIRECT3DDEVICE9 pD3ddev, D3DPRIMITIVETYPE pMethod) const
{
for(sub=0;sub<mSubMeshSize;++sub)
{
pD3ddev->DrawIndexedPrimitive(pMethod,
0,
mSubMeshTable[sub].VertexStart,
mSubMeshTable[sub].VertexCount,
mSubMeshTable[sub].FaceStart*3,
mSubMeshTable[sub].FaceCount);
}
}
Where 'sub' now is a class member. I could simply create a int sub (or something) locally in the function.
Maybe a stupid question, but will the memory of the int will be freed everytime the function finishes?
(would it be a good idea performance wise etc.).