Most often when I see examples on setting the Java heap size using -Xms
and -xmx
JVM parameters people use powers of two:
128m, 512m, 1024m, etc.
Is there actually a reason for this? Is this beneficial to the JVM performance in some way? Or is this simply done because programmers tend to like powers of 2? (Or because the default value is 64m?)
P.S.
Of course I know that you can use essentially any number you want (-Xmx666
). But people tend to use powers of 2.
I can't tell why other people do it but for me, it's a) convention to give RAM sizes in powers of two since the memory modules use that and b) I know all the powers of two up to 65536 from memory, so it's not an extra effort to do it.
But from a OS / memory point of view, using powers of two for allocating megabytes doesn't have any impact. If we were talking about smaller sizes (like 511 or 512 bytes), then the memory management subsystem of the OS will round those values. But no OS rounds for megabytes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With