?
=?iso-8859-1?B?UultaQ==?=
Can someone tell me whether or not my assumptions are good? Just want
to know if I'm going to run into trouble in how I'm deleting map
entries. Although I like to think I know my way around C++, I'm not an
STL expert by any stretch.
Here's a bit of code; notes on my assumptions follow:
_lookupMap is defined as:
map<string, long> _lookupMap;
I'm adding to it something like this:
string * newKey = new string("Some Key Value");
_lookupMap[*newKey] = someIntegerValue;
....and I'm deleting an entry like this (no error checking, assume
find() does actually find...):
string origKey = "Some Key Value";
map<std::string, Int32>::iterator oldEntry = _lookupMap.find(origKey);
const string oldKey = oldEntry->first;
_lookupMap.erase( origKey );
I'm wondering... Will the map object cleanup the string key, or do I
need to delete it myself? Given that the string object is created on
the heap but dereferenced when used as a key, I would assume that the
call to erase will cleanup the string object itself, and I just need to
make sure there aren't any other pointers to the object left lying
around.
Do I have this right?
Remi.
to know if I'm going to run into trouble in how I'm deleting map
entries. Although I like to think I know my way around C++, I'm not an
STL expert by any stretch.
Here's a bit of code; notes on my assumptions follow:
_lookupMap is defined as:
map<string, long> _lookupMap;
I'm adding to it something like this:
string * newKey = new string("Some Key Value");
_lookupMap[*newKey] = someIntegerValue;
....and I'm deleting an entry like this (no error checking, assume
find() does actually find...):
string origKey = "Some Key Value";
map<std::string, Int32>::iterator oldEntry = _lookupMap.find(origKey);
const string oldKey = oldEntry->first;
_lookupMap.erase( origKey );
I'm wondering... Will the map object cleanup the string key, or do I
need to delete it myself? Given that the string object is created on
the heap but dereferenced when used as a key, I would assume that the
call to erase will cleanup the string object itself, and I just need to
make sure there aren't any other pointers to the object left lying
around.
Do I have this right?
Remi.