3 ms·
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
by fauigerzigerk 15y ago
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.
- sliverstorm 15y agoSo what you're saying is, if you want C-like performance in Java, switch to C?
- fauigerzigerk 15y agoExactly, because otherwise you get assembler-like productivity. Specifying memory layouts in Java is much more low level than C or C++ programming.
- rudiger 15y agoIf you truly need C-like performance in Java, use C++.
- srean 15y agoIf 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.
- fauigerzigerk 15y agoD 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)
- peter_lawrey 15y agoI 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)