How to quickly check if a block of memory is zero?

Started by
12 comments, last by JackOfAllTrades 13 years, 4 months ago
Quote:Original post by alagtriste
I don't get the code posted. You are resizing a vector to accomodate point data and then you are growing it with that same data.

Why not just do something along those lines:

*** Source Snippet Removed ***


I see no where in your code that it compares the vertices so you are completely missing the point of the code and when I run that code it loads for 5 minutes, expands my application's memory by over 600MBs then crashes...

Here is my code now btw:

			int ControlPointCount = FBXMesh->GetControlPointsCount();			KFbxVector4* ControlPoints = FBXMesh->GetControlPoints();			AxVertex ZeroVertex = {0};			std::vector<AxVertex> vertices(ControlPointCount);			std::vector<AxFace> faces;			std::vector<int> attributes;			for( int p = 0; p < FBXMesh->GetPolygonCount(); p++ )			{				DWORD indices[4];				for( int i = 0; i < FBXMesh->GetPolygonSize(p); i++ )				{					int vi = FBXMesh->GetPolygonVertex( p, i );					AxVertex vertex = {0};					KFbxVector4 normal;					FBXMesh->GetPolygonVertexNormal( p, i, normal );					vertex.x = (float)ControlPoints[vi][0];					vertex.y = (float)ControlPoints[vi][1];					vertex.z = (float)ControlPoints[vi][2];					vertex.nx = (float)normal[0];					vertex.ny = (float)normal[1];					vertex.nz = (float)normal[2];					if( vertices[vi] != vertex && vertices[vi] != ZeroVertex )					{						indices = vertices.size();						vertices.push_back( vertex );					}					else					{						indices = (DWORD)vi;						vertices[vi] = vertex;					}				}				if(FBXMesh->GetPolygonSize(p) == 4)				{					AxFace face;					face.indices[0] = indices[0];					face.indices[1] = indices[2];					face.indices[2] = indices[3];					faces.push_back( face );					attributes.push_back(1);				}				AxFace face;				face.indices[0] = indices[0];				face.indices[1] = indices[1];				face.indices[2] = indices[2];				faces.push_back( face );				attributes.push_back(1);			}
Advertisement
Quote:Original post by SteveDeFacto
I wrote a function that worked beautifully in python but now I'm trying to convert it to C++. I'm having a problem since in python a list item can be none but the closest thing to this I can do in C++ is check if the item in the vector is zero though it's not perfect it's all I can do.

Basically I have a class that has a few floats in it and I need to check if all the floats are set to zero but I don't want to have to check each variable individually. Is there a way to check if all bits in a block of memory are zero?

Two possible alternative solutions:
1) Use pointers. Check if the pointers are NULL.
2) Overload the cast-to-bool operator, and have a isValid member-variable.

I don't think your solution (checking if everything is 0), is the proper solution for your problem.

[Edit:] Woops, missed a few posts. Nevermind me. *walks off whistling*
Quote:Original post by SteveDeFacto
Quote:Original post by alagtriste
I don't get the code posted. You are resizing a vector to accomodate point data and then you are growing it with that same data.

Why not just do something along those lines:

*** Source Snippet Removed ***


I see no where in your code that it compares the vertices so you are completely missing the point of the code and when I run that code it loads for 5 minutes, expands my application's memory by over 600MBs then crashes...

Here is my code now btw:

*** Source Snippet Removed ***


Yes, I could have missed the point of the code. In fact I don't get it.

Why are you allocating the vertex array with default values and then you are growing it with data?

			std::vector<AxVertex> vertices(ControlPointCount);...					if( vertices[vi] != vertex && vertices[vi] != ZeroVertex )					{						indices = vertices.size();						vertices.push_back( vertex );					}					else					{						indices = (DWORD)vi;						vertices[vi] = vertex;					}				

So if the vertex is not equal to a value or the value is not the default one then insert. Otherwise just overwrite the equal values (?) or defualt value. That piece of code makes no sense to me.

Isn't FBX supposed to be aware of equal vertices allready (If not, why it uses indices for the polingons?), why are you checking for equality. If FBX says they are equal (same index) is because they are the same vertex.

The fact that my code does not compare float values was the whole point of my thread. I've make a litte test and it worked as expected (but I don't really know if is the same thing you are trying to achive beacuse your code makes no sense to me).


Quote:Original post by alagtriste
Quote:Original post by SteveDeFacto
Quote:Original post by alagtriste
I don't get the code posted. You are resizing a vector to accomodate point data and then you are growing it with that same data.

Why not just do something along those lines:

*** Source Snippet Removed ***


I see no where in your code that it compares the vertices so you are completely missing the point of the code and when I run that code it loads for 5 minutes, expands my application's memory by over 600MBs then crashes...

Here is my code now btw:

*** Source Snippet Removed ***


Yes, I could have missed the point of the code. In fact I don't get it.

Why are you allocating the vertex array with default values and then you are growing it with data?

*** Source Snippet Removed ***
So if the vertex is not equal to a value or the value is not the default one then insert. Otherwise just overwrite the equal values (?) or defualt value. That piece of code makes no sense to me.

Isn't FBX supposed to be aware of equal vertices allready (If not, why it uses indices for the polingons?), why are you checking for equality. If FBX says they are equal (same index) is because they are the same vertex.

The fact that my code does not compare float values was the whole point of my thread. I've make a litte test and it worked as expected (but I don't really know if is the same thing you are trying to achive beacuse your code makes no sense to me).


As far as I can tell FBX stores the indices, UVs, and normals per polygon. The idea behind the above code is to split the vertex if the index on the face matches but the normals or UVs don't. Also it splits the polygons to triangles while it's at it though it only works on 4 sided polygons at the moment.

This topic is closed to new replies.

Advertisement