Hello,
I've been using the STL libraries for some time, but still don't know
the ins and outs of its implementation. Could this be because there's
more than 1 implementation?
Does anyone know of a good book out there or article that details how
one should handle memory usage when using the STL data structures,
like vector, map, etc.
Specifically, I mean things like when you put a key (char*) into a
map, does it copy this? Can I delete it right away? Can I only delete
it only after I've finished using my map? What about objects and not
just primitive types.
Same with vector, if I have a vector of myStruct. Do I need to go
through the vector and delete them or does the vector destructor do
that?
In general, I've been going with the rule of if they are pointers, I
am responsible, otherwise the vector class will handle it. But what
if I do:
vector<myObject> myVector;
myObject* obj = new myObject();
myVector.push_back(*obj);
Then what happens? Was this copied? Should I put delete obj here, or
at the end of the program, or never?
You see what I mean. A book that really explains the memory handling
would be very useful. thanks!