How is the speed of the queue and vector C++ classes compared to a normal C type class such as a linked list or C style array. I made a couple typedef's for 3 dimensional arrays and later switched to a class with vectors of size 3 and realized the performance went way down. Is there a way to speed things up in the class by using the original typedef vec3 instead of using vectors? I tried replacing the vector with vec3 but the system fails to run and crashes, and I can't seem to find a way to manage the memory so it does not crash. I deleted and allocated the memory on almost every function, yet it still hits snags.

Code:`typedef float vec2[2]; //2 point vector`

typedef float vec3[3]; //3 point vector

class Vec3{

private:

vector<GLfloat> vect3;

public:

Vec3();

Vec3(double, double, double);

~Vec3();

double* d_array();

GLdouble* GLd_array();

GLfloat* GLf_array();

void Unit();

friend Vec3 operator + (Vec3 a, Vec3 b)

{

Vec3 ret;

ret.vect3[0] = a.vect3[0] + b.vect3[0];

ret.vect3[1] = a.vect3[1] + b.vect3[1];

ret.vect3[2] = a.vect3[2] + b.vect3[2];

return ret;

}

friend Vec3 operator * (Vec3 a, double b)

{

Vec3 ret;

ret.vect3[0] = a.vect3[0] * b;

ret.vect3[1] = a.vect3[1] * b;

ret.vect3[2] = a.vect3[2] * b;

return ret;

}

Vec3 operator = (vec3 a)

{

vect3[0] = a[0];

vect3[1] = a[1];

vect3[2] = a[2];

return *this;

}

Vec3 operator = (double* a)

{

vect3[0] = a[0];

vect3[1] = a[1];

vect3[2] = a[2];

return *this;

}

GLfloat& operator [] (const int a)

{

return vect3[a];

}

GLfloat operator [] (const int a) const

{

return vect3[a];

}

friend Vec3 operator / (Vec3 a, double b)

{

Vec3 ret;

ret.vect3[0] = a.vect3[0] / b;

ret.vect3[1] = a.vect3[1] / b;

ret.vect3[2] = a.vect3[2] / b;

return ret;

}

friend Vec3 operator - (Vec3 a, Vec3 b)

{

Vec3 ret;

ret.vect3[0] = a.vect3[0] - b.vect3[0];

ret.vect3[1] = a.vect3[1] - b.vect3[1];

ret.vect3[2] = a.vect3[2] - b.vect3[2];

return ret;

}

friend Vec3 operator * (Vec3 a, Vec3 b)

{

Vec3 ret;

ret.vect3[0] = a.vect3[0] * b.vect3[0];

ret.vect3[1] = a.vect3[1] * b.vect3[1];

ret.vect3[2] = a.vect3[2] * b.vect3[2];

return ret;

}

friend Vec3 operator / (Vec3 a, Vec3 b)

{

Vec3 ret;

ret.vect3[0] = a.vect3[0] / b.vect3[0];

ret.vect3[1] = a.vect3[1] / b.vect3[1];

ret.vect3[2] = a.vect3[2] / b.vect3[2];

return ret;

}

//this is the same as the cross product

friend Vec3 operator ^ (Vec3 a, Vec3 b)

{

Vec3 ret;

ret.vect3[0] = a.vect3[1]*b.vect3[2] - a.vect3[2]*b.vect3[1];

ret.vect3[1] = a.vect3[2]*b.vect3[0] - a.vect3[0]*b.vect3[2];

ret.vect3[2] = a.vect3[0]*b.vect3[1] - a.vect3[1]*b.vect3[0];

return ret;

}

};

Vec3::Vec3(){

vect3.resize(3); //allocate space for 3 elements

return;

}

Vec3::Vec3(double x, double y, double z){

vect3.resize(3); //allocate space for 3 elements

vect3[0] = x;

vect3[1] = y;

vect3[2] = z;

return;

}

Vec3::~Vec3(){

vect3.clear();

}

double* Vec3::d_array(){

double *ret = new double[3];

ret[0] = (double)vect3[0];

ret[1] = (double)vect3[1];

ret[2] = (double)vect3[2];

return ret;

}

GLdouble* Vec3::GLd_array(){

GLdouble *ret = new GLdouble[3];

ret[0] = (GLdouble)vect3[0];

ret[1] = (GLdouble)vect3[1];

ret[2] = (GLdouble)vect3[2];

return ret;

}

GLfloat* Vec3::GLf_array(){

GLfloat *ret = new GLfloat[3];

ret[0] = vect3[0];

ret[1] = vect3[1];

ret[2] = vect3[2];

return ret;

}

void Vec3::Unit(){

float magn = sqrt(vect3[0]*vect3[0] + vect3[1]*vect3[1] + vect3[2]*vect3[2]);

vect3[0] = vect3[0]*(1/magn);

vect3[1] = vect3[1]*(1/magn);

vect3[2] = vect3[2]*(1/magn);

}