Home » Community » Newbie corner » U ++ Vector vs STL vector
U ++ Vector vs STL vector [message #27334] |
Mon, 12 July 2010 22:02 |
281264
Messages: 270 Registered: June 2010 Location: Spain
|
Experienced Member |
|
|
Hi,
I am interested in knowing the differences, advantages and disadvantages of the Vector and vector. From the reading of the manual I am able to infer that Vector is “lighter” than vector, although I do not (full) understand the topic “deep copy constructor” and “moveable” features.
I will be grateful if someone explains me theses topics.
Thanks and best wishes.
Javier
|
|
|
Re: U ++ Vector vs STL vector [message #27336 is a reply to message #27334] |
Tue, 13 July 2010 00:13 |
Novo
Messages: 1358 Registered: December 2006
|
Ultimate Contributor |
|
|
“moveable” basically means that you can just "move" memory when you want to shift data in memory. You do not need to call a constructor and a destructor in a row. Such a situation happens very often when you want to resize a vector, which stores data in a continuous piece of memory. You just need to move old data into a newly allocated memory. If your data is "moveable" you can just call the memcpy() function instead of calling a copy constructor in a loop.
Hope this helps.
Regards,
Novo
|
|
|
|
Re: U ++ Vector vs STL vector [message #27342 is a reply to message #27334] |
Tue, 13 July 2010 10:16 |
|
The main difference between Vector and vector IMHO is the speed Since for Vector a=b just moves (pickes) the content, instead of copying it into the new container, it is way faster. In real life, most of the operations with containers doesn't care about the content of b after the operation. Sometimes it requires the programmer to think bit more about what he's doing, but the performance gain really pays off (See comparisons). I think I could count on my fingers how many times I had to use the deep copy operator <<=.
Honza
|
|
|
Re: U ++ Vector vs STL vector [message #27347 is a reply to message #27342] |
Tue, 13 July 2010 13:08 |
mrjt
Messages: 705 Registered: March 2007 Location: London
|
Contributor |
|
|
Another great feature is that picking be default allows you to use Vector/Array/other containers as a return type from functions. This greatly reduces the reliance on passing parameters by reference for complicated output.
|
|
|
Goto Forum:
Current Time: Tue May 21 19:49:53 CEST 2024
Total time taken to generate the page: 0.01845 seconds
|