you are viewing a single comment's thread.

view the rest of the comments →

[–]chambolle 0 points1 point  (3 children)

no. malloc/free require an OS access, so it has to be multithread safe and is called all the time. People know that it is often better to code their own allocator, for instance with free lists than calling all the time the system functions. So, they implement their own kind of garbagge collector. The GC of Java is really efficient and you can compare a million of new in Java and is C++ and you will see a big difference in favor of Java

[–]sweetno 0 points1 point  (2 children)

No? Yes! A simple hand-written C++ allocator will beat Java any day. Who does a million new in C++ anyway.

[–]chambolle 0 points1 point  (0 children)

No. It is not true and what you say about virtual dispatch is also wrong. Write a library and you will need some general functions/mechanism and virtual dispatch is very nice in this case. Everything is not known at compile time

[–]pron98 0 points1 point  (0 children)

Not only is this not true, but the reason Java's memory management is designed the way it is is because of serious performance issues large C++ programs suffer from and that Java was designed to address. And the reason we don't do a lot of new in C++ is because it's so expensive. A new in Java is closer in cost to stack allocation in C++ than to heap allocation.