By printing the memoery address given back by 'new', I get:
adding an ideal track: 0xbc03220
adding an ideal track: 0xbc03220
So 'new' operator is giving back an address twice... why does this happen?
I've checked the % of memory used by the program: hardly reaches 10% before crashing.
SbtTrack::SbtTrack(vector<SbtSpacePoint*> aSpacePointList,
SbtEnums::trackType type):
_DebugLevel(0),
_spacePointList(aSpacePointList),
_chi2(0.0),
_ndof(0),
_trackType(type)
{
if (_DebugLevel>0) cout << "SbtTrack: DebugLevel= " << _DebugLevel << "\n" ;
//initiliaze the covariance matrix
_CovX[0][0]=0; _CovX[0][1]=0;
_CovX[1][0]=0; _CovX[1][1]=0;
_CovY[0][0]=0; _CovY[0][1]=0;
_CovY[1][0]=0; _CovY[1][1]=0;
// sort the space points in ascending z position
std::sort( _spacePointList.begin(), _spacePointList.end(), SbtSpacePoint::ltz );
if (type == SbtEnums::idealTrack)
{
try {
SetIdealTrackParms(_spacePointList.at(0),_spacePointList.at(1));
}
catch (std::out_of_range &) {
std::cout << "Caught _spacePointList std::out_of_range\n";
SetIdealTrackParms( NULL, NULL );
}
}
// set default value for residaul
for (int i=0; i< maxTrkNSpacePoint; i++){
_residualX[i]=-999.0;
_residualY[i]=-999.0;
_recoX[i]=-999.0;
_recoY[i]=-999.0;
_fitX[i]=-999.0;
_fitY[i]=-999.0;
}
// digi type are not produced at the moment for simulated tracks
// track are produced directly from SpacePoints
if (_trackType == SbtEnums::recoTrack ) SetIsOnTrack();
}
(a) don't use _name, use name_ if you want. But leading underscores should be avoided (not all cases are reserved, but I don't know the exact rules and I'm pretty sure so do you...)
(b) The constructor has no possibility of changing the return value of new except for throwing an exception (I'm not sure if then the return value is 0 or undefined). So, in short, you posted the wrong code to solve your problem ;-)
(a) don't use _name, use name_ if you want. But leading underscores should be avoided (not all cases are reserved, but I don't know the exact rules and I'm pretty sure so do you...)
It is written in our coding guidelines to use '_' prefix for data members... now I am puzzled...
Anyway:
(b) The constructor has no possibility of changing the return value of new except for throwing an exception (I'm not sure if then the return value is 0 or undefined). So, in short, you posted the wrong code to solve your problem ;-)
I posted the c'tor I call via new.
This is the method (of a different class) that calls that constructor:
It is written in our coding guidelines to use '_' prefix for data members
Well, your coding standard, like most I've seen, sucks. The problem: the standard only reserves leading-underscore-names in the global namespace (so it *should* be OK for members). BUT implementations tend to use macros, which don't observe namespaces, and I doubt that any implementation out there is really 100% compatible with this rule. So, avoid leading underscores and double underscores (see also Sutter: "Exceptional C++", p. 74, where I looked it up just for you to be sure I don't tell you something wrong ;-) ).
The rest of the code, if you use it seperately, should work. I don't see an error in it. But then again, it isn't much. Are you sure you don't try to delete the same pointer twice?
So 'new' operator is giving back an address twice...
New is implemented like
1 2 3 4
void* operatornew(size_t s)
{
return malloc(s);
}
so it really isn't anything the constructor can screw (except for overwriting this returned address... which is rather unlikely)
The Image2D's private ImageData structure keeps all the important information in a shared, dynamically-allocated, reference-counted piece of memory, so it is only deleted when all instances of the object are destroyed.