So to deal with large blobs of memory either for an image or similar there are clearly lots of options.
Since I'm a fan of smart pointers and RAII I'm wondering about whether it's smarter to go with :
- a
shared_ptr
to astd::vector
or
- to go with a
shared_array
pointing to a dynamically allocated array.
What are the conceptual, practical, and performance implications of choosing one vs the other?
std::vector
? when shared_* is used it usually means there is no owner, which is frequently a desing defect. – Loshared_ptr
and friends (or other smart pointer implementations), they are used only when there are multiple simultaneous owners with lifetimes that cannot be determined during compile time. Granted they don't occur often, but they have a legitimate use. – Melisamelisandevector
isswap()
. You should only needshared_ptr<vector<T> >
when you're actually using the refcounting, that is when multiple different owners need to access the same vector, and you don't know which one will need it longest. – Benningtonunique_ptr
. – Lo