If you don\'t need dynamic growth and don\'t know the size of the buffer at compile time, when should unique_ptr
be used instead of vector<
Objective Part:
No, there probably shouldn't be a significant performance difference between the two (though I suppose it depends on the implementation and you should measure if it's critical).
Subjective Part:
std::vector
is going to give you a well known interface with .size()
and .at()
and iterators, which will play nicely with all sorts of other code. Using std::unique_ptr
gives you a more primitive interface and makes you keep track of details (like the size) separately. Therefore, barring other constraints, I would prefer std::vector
.