c++ - Building an index: Copies or pointers? -
I have a data structure that stores ... well, data. Now, I need to reach different pieces of data in a slightly different way, so I'm essentially building an in-memory index. But I'm thinking: should there be index pointers or copies?
To expand, say that I have
class widget {// how to access the list of gear .. private: std :: list & lt; Gears & gt; M_gears; };
Now, I have two widgets
s, and between them there is a mapping between their gear
s presently , This
boost :: unmodified_map> Gear, gear & gt;
But gear
is quite heavy square, and I think making such copies is bad design. I can store an indicator, but then mapping is valid for the lifetime of this widget
s, and you can call - & gt;
s ... (and if the std :: list
turns into std :: vector
, it becomes more complex Is ...)
In relation to copies, it is actually a bit bad: two boost :: unordered_map
s, one for each direction, therefore, every gear For
, I'm making it up to 2 copies.
Alternatively, I can put the index inside the widget
class, but I think it violates the widget
class responsibilities .
You can try Boost Pointer Container Library:
I think That this is exactly the problem you are facing.
Comments
Post a Comment