c++ - Should I store entire objects, or pointers to objects in containers? -
designing new system scratch. i'll using stl store lists , maps of long-live objects.
question: should ensure objects have copy constructors , store copies of objects within stl containers, or better manage life & scope myself , store pointers objects in stl containers?
i realize short on details, i'm looking "theoretical" better answer if exists, since know both of these solutions possible.
two obvious disadvantage playing pointers: 1) must manage allocation/deallocation of these objects myself in scope beyond stl. 2) cannot create temp object on stack , add containers.
is there else i'm missing?
since people chiming in on efficency of using pointers.
if you're considering using std::vector , if updates few , iterate on collection , it's non polymorphic type storing object "copies" more efficent since you'll better locality of reference.
otoh, if updates common storing pointers save copy/relocation costs.
Comments
Post a Comment