News for hackers. Stuff that matters.
Re:In what cases is Java faster than C++? by albertzeyer on Wednesday February 16, 2011 @11:04AM (#2226907)
I guess both Java and OCaml will see that the object can be generated on the stack which makes it much faster.

By using malloc in the C implementation, you force it to be on the heap.

Re:In what cases is Java faster than C++? by thelema314 on Wednesday February 16, 2011 @01:23PM (#2227539)
Actually, OCaml never generates objects like this on the stack - value creation is always taken literally. The OCaml compiler is really allocating all those records. It's just that their lifetime is almost zero, so the cost to clean them up is zero (as none get promoted from the minor heap to the major heap). And the cost to create them is almost zero, just a += and a compare.
Re:In what cases is Java faster than C++? by albertzeyer on Wednesday February 16, 2011 @04:18PM (#2228345)
Ah, interesting. Does it also have a GC or some own custom allocation implementation?

Because if it really would use something like malloc, I don't really see how it should be faster than the C version.