Java performance: Difference between revisions

Content deleted Content added
m Reverted edits by Roman_ali12 (talk): addition of unnecessary/inappropriate external links (HG) (3.4.10)
Citation bot (talk | contribs)
Add: title. Changed bare reference to CS1/2. | Use this bot. Report bugs. | Suggested by BrownHairedGirl | Linked from User:BrownHairedGirl/Articles_with_bare_links | #UCB_webform_linked 559/2846
Line 366:
{{Disputed section|Most_of_the_memory_use_section_is_really_odd_nitpicks|date=August 2019}}
Java memory use is much higher than C++'s memory use because:
*There is an overhead of 8 bytes for each object and 12 bytes for each array<ref>{{Cite web|url=http://www.javamex.com/tutorials/memory/object_memory_usage.shtml|title = How to calculate the memory usage of Java objects}}</ref> in Java. If the size of an object is not a multiple of 8 bytes, it is rounded up to next multiple of 8. This means an object holding one byte field occupies 16 bytes and needs a 4-byte reference. C++ also allocates a [[Pointer (computer programming)|pointer]] (usually 4 or 8 bytes) for every object which class directly or indirectly declares [[virtual function]]s.<ref>{{cite web |url=http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=195 |title=Archived copy |access-date=June 22, 2009 |url-status=dead |archive-url=https://web.archive.org/web/20080221131118/http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=195 |archive-date=February 21, 2008 |df=dmy-all }}</ref>
*Lack of address arithmetic makes creating memory-efficient containers, such as tightly spaced structures and [[XOR linked list]]s, currently impossible ([[Project Valhalla (Java language)|the OpenJDK Valhalla project]] aims to mitigate these issues, though it does not aim to introduce pointer arithmetic; this cannot be done in a garbage collected environment).
*Contrary to malloc and new, the average performance overhead of garbage collection asymptotically nears zero (more accurately, one CPU cycle) as the heap size increases.<ref>https://www.youtube.com/watch?v=M91w0SBZ-wc : Understanding Java Garbage Collection - a talk by Gil Tene at JavaOne</ref>
*Parts of the [[Java Class Library]] must load before program execution (at least the classes used within a program).<ref>{{Cite web|url=http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html|title = .: ToMMTi-Systems :: Hinter den Kulissen moderner 3D-Hardware}}</ref> This leads to a significant memory overhead for small applications.{{citation needed|date=January 2012}}
*Both the Java binary and native recompilations will typically be in memory.
*The virtual machine uses substantial memory.