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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -