News for hackers. Stuff that matters.
Re:How to get C like performance in Java by fauigerzigerk on Wednesday July 20, 2011 @02:58PM (#2786957)
I've been working very hard to make Java use less memory using techniques like these and others more. The problem is, if you really want to specify exactly how non-trivial structured objects are packed into memory, you end up writing your own garbage collector and memory allocator, which is a rather large project all by itself. Also, I have found that cutting down on memory usage like that hurts performance a lot.

At the end of the day, going down that road makes you less productive than working in C++ and the result will still be subpar compared to a C or C++ solution. So I'm back with C++ right now even though I'm painfully aware of its weaknesses.

Re:How to get C like performance in Java by srean on Wednesday July 20, 2011 @04:52PM (#2787388)
If you are coming back to C++ after a stint with Java, I would highly recommend D. I think it hits the sweetspot between C++ and Java. The not so nice thing about D is that its libraries are not as pervasive and mature. The Phobos and Tango split is currently being addressed. I think all of Tango's functionality will be incorporated into Phobos. With D you get a simpler C++ with optional automatic memory management, and some functional idioms and nice support for parallelism.

@down-voter: If you could explain what you found down-vote worthy that would be nice.

Re:How to get C like performance in Java by fauigerzigerk on Wednesday July 20, 2011 @06:14PM (#2787642)
D looks interesting, but I'm a little concerned that the libraries may not be robust or comprehensive enough yet. It's an uphill battle for any new language.

(downvoters are indeed a mystery sometimes)

Re:How to get C like performance in Java by sliverstorm on Wednesday July 20, 2011 @04:04PM (#2787179)
So what you're saying is, if you want C-like performance in Java, switch to C?
Re:How to get C like performance in Java by fauigerzigerk on Wednesday July 20, 2011 @04:08PM (#2787201)
Exactly, because otherwise you get assembler-like productivity. Specifying memory layouts in Java is much more low level than C or C++ programming.
Re:How to get C like performance in Java by rudiger on Wednesday July 20, 2011 @04:06PM (#2787189)
If you truly need C-like performance in Java, use C++.
Re:How to get C like performance in Java by peter_lawrey on Thursday July 21, 2011 @04:23AM (#2788854)
I would say I am less concerned about how memory is packed, than how much is discarded. This is because memory is relatively cheap these days. A machine with 24 GB of memory costs around £1K. However you make a good point that C++ gives you better control over how memory is arranged and you have to use hacks like the Unsafe class in Java (which is not as friendly)