The performance cost associated with std::vector.

J

Jason Heyes

What harmful effects can using std::vector have on the performance of my
program? How do I protect my program from these effects? Thanks.
 
B

Bob Hairgrove

What harmful effects can using std::vector have on the performance of my
program? How do I protect my program from these effects? Thanks.

I think a more appropriate question would be:

"What harmful effects can NOT using std::vector have on the
performance of my program? How do I protect my program from these
effects?"
 
B

Bob Jacobs

Jason Heyes said:
What harmful effects can using std::vector have on the performance of my
program? How do I protect my program from these effects? Thanks.

Performance compared with what?
 
S

Samuele Armondi

Jason Heyes said:
What harmful effects can using std::vector have on the performance of my
program? How do I protect my program from these effects? Thanks.
On most implementations, perfomance is similar to an array, but it should
not be hard to code a little test to find out how your particular
implementation measures up... The advantages of using a vector (like safety
from memory management problems and the like) far outweigh any perfomance
penalties for all but the most time-critical applications.
HTH,
S. Armondi
 
T

tom_usenet

What harmful effects can using std::vector have on the performance of my
program? How do I protect my program from these effects? Thanks.

Compared against dynamic allocation using malloc/new[], you really
only have minor concerns that I can think of.

1. Vector elements are initialized when you resize. You can avoid this
where it has caused a performance problem by using push_back to add
elements (having reserved enough space).

2. Avoid copying vectors (or passing by value) unless you really want
to perform a deep copy.

Apart from that, performance should be close to identical to a
hand-coded hand-optimized malloc-based array using exponential
expansion.

Tom

C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top