Re: about new and delete
Sam <s...@email-scan.com> wrote:
SG writes:
Sam <s...@email-scan.com> wrote:
I'm sorry that I disappointed you, by failing to come up with the
meaningless results that you were so much looking for.
I wouldn't use the word "disappointing". But the I'm-righter-than-you-
are-and-proud-of-it attitude we can see here isn't going to help
anybody. It certainly doesn't improve your popularity.
When I actually decide to enter some kind of a popularity contest, I'll let
you know.
(splicing, insert, ... etc) a vector is both faster and consumes less
memory.
Yes. All the additional array elements that are held in reserve, for future
vector growth, really uses something called "hypothetical memory", instead
of the real one. I didn't know that!
Now, you know. Knowing is half the battle.
Seriously, with T=int I still expect it to be more efficient even with
the reserved memory and in the worst case scenario where a vector
needs to grow. I have no reason to believe otherwise. What do you
think is the overhead for allocating a list node?
You're right in that the containers' performance depends on T.
Summarization:
In case it's only about appending elements to a container and
iterating through it both kinds of container can be used. There is a
certain sizeof(T) value above which std::list comsumes less memory and
below that std::vector consumes less memory. There's also a certain
copy construction cost (time) above which std::list will be faster and
below that std::vector will be faster -- all assuming the exact size
is not known beforehand.
allocation overhead. For testing the speed I created & destroyed an
int-container 5000 times and each time filled it (push_back) with
Poor OP. He must've spent a lot of time meticulously typing in all those
5000 ints that his test program prompted for.
What does the size have to do with anything? The excecution time and
memory usage scales linearly with the number of elements on both
containers!
As for the user not wanting to type in 5000 ints: Why do you even
bring up your memory cost argument?!
Cheers,
SG