Should they be used all the time? If so what is the point of have the "new" and "delete" operators? I'm guessing that vectors can sometimes slow things down a bit.
On a side note, I've got a rather complex algorithm, with lots of news and deletes, and things just don't quite look right to me. Here is a section of the code:
Code:
#include <cmath>
#include "poly.hpp"
poly::poly () {
corners = new point[3];
pvrt = new vertice[3];
}
poly::~poly () {
delete[] corners;
delete[] pvrt;
}
poly &poly::operator =(const poly &rhs){
if(this != &rhs){
int i;
A = rhs.A;
B = rhs.B;
C = rhs.C;
D = rhs.D;
n = rhs.n;
beta = rhs.beta;
norm = rhs.norm;
delete[] corners;
corners = new point[n];
delete[] pvrt;
pvrt = new vertice[n];
for(i=0;i<n;i++){
corners[i] = rhs.corners[i];
pvrt[i] = rhs.pvrt[i];
}
}
return *this;
}
I could certainly justify using new and delete though, if it is faster that way. This program does tree-like recursion which can take a lot of time.