vector class memory usage [modified]
-
I am just wondering if this:
class Vector
{
public:
float x,y,z;
};
Vector v;differs from this:
class Vector
{
public:
float x,y,z;
void Cross(Vector, Vector);
void Dot(Vector, Vector);
void Normalize();
//etc.....
};
Vector v;in terms of performance.
modified on Friday, June 4, 2010 1:56 PM
-
I am just wondering if this:
class Vector
{
public:
float x,y,z;
};
Vector v;differs from this:
class Vector
{
public:
float x,y,z;
void Cross(Vector, Vector);
void Dot(Vector, Vector);
void Normalize();
//etc.....
};
Vector v;in terms of performance.
modified on Friday, June 4, 2010 1:56 PM
What do you mean by "performances" ? If you mean memory size (which I guess you mean because speed is irrelevant here): there's little difference between the two. The methods of a class are in fact not contained in each instance of the class (which means that if you instantiate 10.000 classes, the methods in the class won't have a big impact on the memory consumption). Does that answer your question ?
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
I am just wondering if this:
class Vector
{
public:
float x,y,z;
};
Vector v;differs from this:
class Vector
{
public:
float x,y,z;
void Cross(Vector, Vector);
void Dot(Vector, Vector);
void Normalize();
//etc.....
};
Vector v;in terms of performance.
modified on Friday, June 4, 2010 1:56 PM
what's the question ? performance is dependant on a whole lot of different factors! memory usage ? computation speed ? AFAIK, adding member function to a class does not really impact on performance.
Watched code never compiles.
-
I am just wondering if this:
class Vector
{
public:
float x,y,z;
};
Vector v;differs from this:
class Vector
{
public:
float x,y,z;
void Cross(Vector, Vector);
void Dot(Vector, Vector);
void Normalize();
//etc.....
};
Vector v;in terms of performance.
modified on Friday, June 4, 2010 1:56 PM
If you mean does implementing operations on a class as member functions add any overhead to the time it takes to execute those operations compared to an equivalent global function then the answer is no. If you use virtual functions then there's a bit of additional overhead but it's pretty minimal compared to dividing two floating point numbers. Cheers, Ash