Reputation: 21
I'm writing a parallel implementation of some data structures. I'd like to find out if someone know about difference in performance between pure pointers and std::vector. If you know trustful docs about it, please write URL/book name/whatever. Any hints are welcome!
Upvotes: 2
Views: 295
Reputation: 59811
If you mean to compare a std::vector
with some hand-written dynamic array here are some points of reference:
std::vector
if you call vector::at
which cannot happen with raw pointers.Upvotes: 0
Reputation: 9893
According to this answer in a similar question, accessing an element in a dynamically-allocated array versus a std::vector
will be roughly the same. There's some good analysis in that question and in this one as well.
Upvotes: 0
Reputation: 146920
You can make std::vector as fast as normal pointers by using the unchecked operator[] and resizing appropriately. The reality is that vector is a compile-time abstraction over a pointer- not a runtime one, unless you choose to use extras. What's much more important is the vastly increased safety vector offers- debugging iterators, automatic and safe resource management, etc. There is no reason to use a raw pointer.
Edit: My reference is that profiling run you did before you even considered losing the safety of vector.
Upvotes: 3