struct VECTOR {
float *vx,*vy,*vz; // xyz verticies
float *cu,*cv; // uv texture coords
float *nx,*ny,*nz; // xyz normals
};
struct OBJ3D {
int objStyle;
VECTOR *obj;
};
clsObject::~clsObject() {
delete obj3D;
}
int clsObject::init_obj3D() {
obj3D = new OBJ3D; // create single allocation
obj3D->objStyle = GL_TRIANGLES;
obj3D->obj->vx = new int[32];
obj3D->obj->vy = new int[32];
obj3D->obj->vz = new int[32];
}
I fseek, therefore I fam.
delete[] and aliasing questions
1) Can I just do a delete obj3D or do I need to delete[] the members first, then delete the whole object?
2) Is it possible to alias so I don''t end up with something like:
instead of.. object->face->obj[3].vx
have.. of[3].vx
?
if you have an object:
you must delete the memory you allocated in this object. if you
don''t do, you have a memory leak:
you could do this by defining a destructor, i think:
struct obj{ int *ptr; obj () { ptr = new int[32]; }}
you must delete the memory you allocated in this object. if you
don''t do, you have a memory leak:
obj *o_ptr = new obj (); // allocationdelete [] o_ptr->ptr; // deallocationdelete o_ptr; // deallocation
you could do this by defining a destructor, i think:
obj::~obj (){ if (ptr) { delete [] ptr; ptr = (int *)0; }}
You should give your struct a destructor to call delete[] on each of those pointers. That way your class can simply call delete on the struct and it will carry through to delete the pointers.
Look up references (AKA aliases, now there''s a pun ).
______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________
______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement