I have a map<EntityState, boost::weak_ptr<Animation>>
in my EntityRepresentation
class. I would kinda want to create a Builder class for the representation, but I have to consider the costs of copying the map.
EntityState
is cheap to copy since it's just a collection of static functions; boost::weak_ptr
is also cheap to copy. How about the map as a whole?
Yes -- when you insert an item into an std::map, you pass it by value, so what it contains is a copy of what you passed.
Don't optimize prematurely. In many scenarios the run-time performance of a builder class will not be the bottleneck.
Generally, the complexity of copying a map is O(n)
. From the comments, it looks like n
is small. If you've identified that you really need to optimize, then in such a case, using two vectors will be cheaper both in accessing the items, and in the copying.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With