Destructionator XIII wrote:What would be more interesting is dynamically altering the size of the array / vector and see which one wins. That is the main advantage of a vector anyway; resizing without worring about details like realloc'ing it yourself. It is late tonight, but if no one tackles this by the time I wake up tomorrow morning, I will write up a sample program to test it out. Should be fascinating.
For any significantly-sized array, most of the time spent resizing is going to be in memcpy(). Any overhead from the vector class's management would be insignificant (constant time overhead as opposed to linear time memcopy()). And as we've seen so far, the overhead may mostly be removed by turning optimization on.
And if you're going for speed, you shouldn't be allocating memory during your time-intensive operations anyway. You should guess how much you'll need and preallocate it anyway.
And if you're contemplating using standard arrays for performance instead of a vector (not that it matters as seen here), then you probably know how much memory you're going to need for a static array anyway. (What serious programmer doing serious work is going to roll their own memory management solution and risk introducing unnecessary bugs and memory leaks when the STL is available at essentially no performance cost? Outside of a few rare circumstances, it just doesn't make any sense.)
Later...