I have an X class that I would like to put in an STL map like std :: map. An STL card must have an X stored in memory somewhere, so I'm looking for an efficient way (runtime and memory) to create an X and save it on the map.
I noticed that the following code, where x is an object of type X and stlMap, is a map of type std :: map:
stlMap["test"] = x;
The following results are called up:
- Default constructor X
- X Copy Constructor
- X Copy Constructor
- X destructor
- X destructor
- Assignment Constructor X
- X destructor
Why are so many X objects being created?
Is it an inefficient use of time and memory?
Is there a better way to put an object on a map? Maybe changing the map will be displaying rows in x *?
source
share