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_ptrto astd::vector
or
- to go with a
shared_arraypointing 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.shared_ptrand 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.vectorisswap(). 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.