c++ - shared_ptr to vector of shared_ptr -
i have following class
struct images { std::vector< std::shared_ptr<byte[]> > ptr_vector; }
wouldn't putting ptr_vector
in std::shared_ptr
more efficient when copying images
? namely doing images a; images b = a;
struct images { std::shared_ptr< std::vector<std::shared_ptr<byte[]>> > vector_ptr; }
instead of copying vector , increment multiple shared_ptr reference count, 1 performed here.
is there problem/limitation approach?
yes, copying more efficient, if must copy pointer only.
the limitation pointer, share common data. when modify 1 struct images
other 1 modified well.
if want share data, can think having std::shared_ptr<images>
struct images { std::vector< std::shared_ptr<byte[]> > ptr_vector; }; std::shared_ptr<images> images1, images2;
this avoid copying large data sets well.
Comments
Post a Comment