I see many many usage as pointer to a vector in some third party library. I never use containers that way and wondering what is the rational behind it? Save memory?
Thanks
In C++, there's really not much advantage of a reference to a vector and a pointer to a vector. A reference to a vector is used more often than not here. Also, there is no point in allocating memory on the heap for a vector if that's what your using the pointer for.
1) your application now has to manage the memory (objects are probably dynamically allocated)
2) any good programmer will check for NULL before dereferencing any of the pointers contained in the vector,
meaning extra (unneeded) error legs
3) the extra dereference needed to access the real value makes using some boost libraries (such as lambda)
with STL algorithms nastier.
saving pointers in vector or in any container instead of full object will give better performance. item 3, effective stl, scott meyers.
You need to qualify why here, since it's not always the case. At other times storing the full object can be better for performance. There's never a silver bullet in C++ or other languages for that matter, it's always trade offs.
Google what? Why should I have to google anything when you asked the question? I was asking for some code from a particular 3rd party library where you said that you saw a vector being used in that way. How would I know what to search for?