Sign in to follow this  
ryt

wich of these two is faster?

Recommended Posts

Wich of these two is faster? This one: for(int i = 0; i < numberOfVerticesVertices; i++) { pVertices[i] = vector3(0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(0, 0, 0, 0)); } or this one: memset(pVertices, 0, sizeof(vector3)*numberOfVerticesVertices);

Share this post


Link to post
Share on other sites
1. They don't do the same thing.
2. They're both useless, anyway.
3. It depends on the padding in the vector3 structure.
4. It also depends on the number of vertices.
5. It also depends on the vector3 constructor.
6. Assuming no padding and many vectors, the first will not be faster.
7. Use a profiler to determine the correct answer.

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
1. They don't do the same thing.
2. They're both useless, anyway.

These are the points you should focus on. Why do you want to initialize the array?(or what are you trying to do?) When loading the 3d model you will overwrite those zeros anyway.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kambiz
Quote:
Original post by ToohrVyk
1. They don't do the same thing.
2. They're both useless, anyway.

These are the points you should focus on. Why do you want to initialize the array?(or what are you trying to do?) When loading the 3d model you will overwrite those zeros anyway.


In render look I change vertices of a mesh. I use += so they move relative to what position they had before. I must initialize to 0 so then I can recompute all vertices and have exact position. I dont want to leave positions untouched cos than to find new positions I would need to compute new positions and interpolate between new positions and old ones.

Share this post


Link to post
Share on other sites
Quote:
Original post by ryt
In render look I change vertices of a mesh. I use += so they move relative to what position they had before. I must initialize to 0 so then I can recompute all vertices and have exact position. I dont want to leave positions untouched cos than to find new positions I would need to compute new positions and interpolate between new positions and old ones.


And? If you are doing this every frame, then instead of:
float f = 0.0f; 
f += delta;
use:
float f = delta;
and skip the initialize-to-zero altogether.

If you're doing this once at initialization time, the speed difference is pointless.

Share this post


Link to post
Share on other sites
This is the code:

memset(pVertices, 0, sizeof(vector3)*numberOfVerticesVertices);
for(int V = 0; V < numberOfVerticesPerColumnVertices; V++)
{
for(int U = 0; U < numberOfVerticesPerRowVertices; U++)
{
for(int i = 0; i < numberOfVerticesPerColumnControlPoint; i++)
{
for(int j = 0; j < numberOfVerticesPerRowControlPoint; j++)
{
int controlPoint = i*numberOfVerticesPerRowControlPoint+j;
int vertex = V*numberOfVerticesPerRowVertices+U;
pVertices[vertex]._x += pControlPoints[controlPoint]._x*pStoredBasisFunction[vertex*numberOfVerticesControlPoint+controlPoint];
pVertices[vertex]._y += pControlPoints[controlPoint]._y*pStoredBasisFunction[vertex*numberOfVerticesControlPoint+controlPoint];
pVertices[vertex]._z += pControlPoints[controlPoint]._z*pStoredBasisFunction[vertex*numberOfVerticesControlPoint+controlPoint];
pVertices[vertex]._color = D3DCOLOR_ARGB(255, 200, 255, 255);
}
}
}
}



I think I understand what u meant, I need too think abaut it

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this