|
-
August 1st, 2012, 08:16 PM
#1
delete vector of objects, single objects, dealocate menory
I have been reading around a bit and there seems to be no straightforward way to do this.
I have a global vector of objects and a single object that I need to delete as part of the re-initialization of a function that use the global data. Something like,
Code:
class dataSet {
public:
// initialize class members
dataSet ()
: max(0),
numA(0),
numB(0),
numR(0) { }
int max, numA, numB, numR;
};
class CurrentInfo {
public:
// initialize class members
CurrentInfo()
: aES(0.0), aHES(0.0), saES(0.0),
aNum(0), atNum(0), aType(0), delta(0),
hbd(false), hba(false) { }
bool hbd, hba;
int aNum, atNum, aType, delta;
float aES, aHES, saES;
string ordLookup;
vector<int> nNums, nOrds, distance;
};
These have global declarations,
Code:
extern vector<CurrentInfo> current;
extern dataSet newSet;
There is another function that needs to reset these structures in preparation for new data.
I think I can do something like,
Code:
vector<CurrentInfo>().swap(current); // will this work ???
to get rid of the vector of objects, but I'm not sure how to get rid of the single object.
It seems as if there should be a simple command to delete and de-allocate memory that would go along with new. These objects will be re-created later, so it is possible that I could just remove the data and leave the object in place to be filled with new data.
current.erase(current.begin(), current.end());
I am in a complicated bit of debugging right now and it would be much easier for the present to just make them go away.
LMHmedchem
Last edited by LMHmedchem; August 1st, 2012 at 08:27 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|