[...]
It does very much so. Dynamically allocating a huge number of very
small objects is perhaps something you do in Java, but you don't do
that in real C++ code. Especially not in a loop.
This also holds with regards to Peter Koch's comment "new is
quite rare": it depends. You're certainly not forced to use new
for everything (nor should you), but there are specific
applications where you might end up with such allocation
patterns.
That might be one reason why C++ implementors haven't spent
much effort optimizing this.
Some have, actually, and there are implementations of
malloc/free which handle a lot of small allocations gracefully.
I can have a std::vector<item> or a std::deque<item> and don't
have to use new in my code. The container can grow as needed.
Up until that point, the same holds true in Java. The
difference is that in Java, when you have a vector of item, what
you really have is a vector of pointers to item, and each item
has to be allocated individually. If my goal were to write a
benchmark proving C++ were faster than Java, I'd certainly start
by defining a small class, like Point (two or three double) or
Complex (two double), then start deap copying vectors of them.
Java memory allocation can be very fast, but not as fast as 0.
(If I really wanted Java to look bad, I'd also arrange things so
that the garbage collector pool space was almost full, almost
all of the time, so that the garbage collector had to run often,
on a lot of allocated memory.)
Of course, if I wanted to prove Java faster, I'd choose
something else. Never trust a benchmark you having falsified
yourself.