W
will551
hi guys
Im having a problem with map inserts. The destructor is being called
for the element I have just added:
Here is some code:
char *recorderName = "blah";
char *mProtoRecorder = "blah";
cout << "in ::FindOrCreateRecorder..."
recorder = new TINRecorder<long long>(recorderName, mProtoRecorder);
mTheMap->insert(mTheMap::value_type(recorderName, *recorder));
printf("about to delete recorder [%p]\n, recorder);
delete recorder;
*iter = mTheMap->find(recorderName);
printf("iter address is [%p]\n", iter);
printf("iter->first address is [%p]\n", &((*iter)->first));
printf("iter->second address is [%p]\n", &((*iter)->second));
cout << "returning... " << endl;
return;
once I hit this point the destructor is called for the recorder even
though
I have already called the recorder delete. The strange thing is that
the address
of the recorder is not the address of the local variable. It is nearer
the address
of the iterator. In fact it is "a8" bytes (168) away from the start of
the iterator.
Here is the output to screen:
in ::FindOrCreateRecorder...
TINRecorder cons "this:" [14f0a68]
about to delete recorder [14f0a68]
~TINRecorder this: [14f0a68]
iter address is [ffb4f7e8]
iter->first address is [14fccb8]
iter->second address is [14fccbc]
returning...
~TINRecorder this: [ffb4f740] <--- Destructor called again here
(address a8 away from iter)
Im having a problem with map inserts. The destructor is being called
for the element I have just added:
Here is some code:
char *recorderName = "blah";
char *mProtoRecorder = "blah";
cout << "in ::FindOrCreateRecorder..."
recorder = new TINRecorder<long long>(recorderName, mProtoRecorder);
mTheMap->insert(mTheMap::value_type(recorderName, *recorder));
printf("about to delete recorder [%p]\n, recorder);
delete recorder;
*iter = mTheMap->find(recorderName);
printf("iter address is [%p]\n", iter);
printf("iter->first address is [%p]\n", &((*iter)->first));
printf("iter->second address is [%p]\n", &((*iter)->second));
cout << "returning... " << endl;
return;
once I hit this point the destructor is called for the recorder even
though
I have already called the recorder delete. The strange thing is that
the address
of the recorder is not the address of the local variable. It is nearer
the address
of the iterator. In fact it is "a8" bytes (168) away from the start of
the iterator.
Here is the output to screen:
in ::FindOrCreateRecorder...
TINRecorder cons "this:" [14f0a68]
about to delete recorder [14f0a68]
~TINRecorder this: [14f0a68]
iter address is [ffb4f7e8]
iter->first address is [14fccb8]
iter->second address is [14fccbc]
returning...
~TINRecorder this: [ffb4f740] <--- Destructor called again here
(address a8 away from iter)