3 ms·
This is because the JVM preallocates a bunch of memory to manage its own heap and doesn't need to make a system call and suffer a userspace/kernel space context
by nonameiguess 5y ago
This is because the JVM preallocates a bunch of memory to manage its own heap and doesn't need to make a system call and suffer a userspace/kernel space context switch every time you use the new operator. Plenty of C++ memory pool libraries will do exactly the same thing for you; it's just not built into the language runtime itself, as you don't necessarily need it if you aren't going to be doing heap allocations at all. In Java, you really have no choice unless you're writing some extremely simple toy program that only uses primitive types, at which point why are you bothering to use Java?