M
Michael
If I am going to be using the same class over and over again passing between
functions, would the following be quicker (as the constructor wouldn't have
to be called):
//First Example:
class MVector{
float x,y,z;
MVector() {x=y=z=0);
};
class MBoundingBox
{
MVector GetCentreVector() {/* Gets Vector */}
};
MVector vec;
MBoundingBox BB[1000];
for(int i=0;i<10000;i++)
{
vec = BB.GetCentreVector();
/* do something */
}
//Second Example:
class MVector{
float x,y,z;
MVector() {x=y=z=0);
};
class MBoundingBox
{
void GetCentreVector(MVector& vec) { /* put vec into reference */}
};
MVector vec;
MBoundingBox BB[1000];
for(int i=0;i<10000;i++)
{
BB.GetCentreVector(vec);
/* do something */
}
ie is it quicker to pass by reference than to return by value??
Regards
Michael
functions, would the following be quicker (as the constructor wouldn't have
to be called):
//First Example:
class MVector{
float x,y,z;
MVector() {x=y=z=0);
};
class MBoundingBox
{
MVector GetCentreVector() {/* Gets Vector */}
};
MVector vec;
MBoundingBox BB[1000];
for(int i=0;i<10000;i++)
{
vec = BB.GetCentreVector();
/* do something */
}
//Second Example:
class MVector{
float x,y,z;
MVector() {x=y=z=0);
};
class MBoundingBox
{
void GetCentreVector(MVector& vec) { /* put vec into reference */}
};
MVector vec;
MBoundingBox BB[1000];
for(int i=0;i<10000;i++)
{
BB.GetCentreVector(vec);
/* do something */
}
ie is it quicker to pass by reference than to return by value??
Regards
Michael