使用32位JVM执行以下java语句后分配了多少字节的内存[重复]

时间:2021-04-08 10:00:19

This question already has an answer here:

这个问题在这里已有答案:

How much bytes of memory are allocated after the following java statement is executed using a 32 bit JVM (assume that a memory reference contains only the first address of location being referenced)?

使用32位JVM执行以下java语句后,分配了多少字节的内存(假设内存引用只包含被引用位置的第一个地址)?

int a = new int[20];

2 个解决方案

#1


2  

80 bytes for the array itself (4 bytes for an int in a 32-bit system/jvm). Not sure about the variable. But you have numerous problems. One, you're assigning an int array to an int--that won't compile. Two, your question's lone tag is for javascript, which makes me assume that you don't know that javascript and java are different, which makes me wonder why you're concerned with memory allocation at the primitive level at this point in your educational journey.

数组本身为80字节(32位系统中的int为4字节/ jvm)。不确定变量。但是你有很多问题。一,你将一个int数组赋给一个int - 它不会编译。二,你的问题的单独标签是针对javascript的,这让我假设你不知道javascript和java是不同的,这让我想知道为什么你在教育历程中关注原始级别的内存分配。

#2


2  

The int(s) use 4 * 20 bytes. The OpenJDK/Oracle JVM, the header uses 12 bytes, but objects have an 8 byte alignment.

int(s)使用4 * 20字节。 OpenJDK / Oracle JVM,标头使用12个字节,但对象具有8字节对齐。

So the total memory used would be 96 bytes.

所以使用的总内存为96字节。

#1


2  

80 bytes for the array itself (4 bytes for an int in a 32-bit system/jvm). Not sure about the variable. But you have numerous problems. One, you're assigning an int array to an int--that won't compile. Two, your question's lone tag is for javascript, which makes me assume that you don't know that javascript and java are different, which makes me wonder why you're concerned with memory allocation at the primitive level at this point in your educational journey.

数组本身为80字节(32位系统中的int为4字节/ jvm)。不确定变量。但是你有很多问题。一,你将一个int数组赋给一个int - 它不会编译。二,你的问题的单独标签是针对javascript的,这让我假设你不知道javascript和java是不同的,这让我想知道为什么你在教育历程中关注原始级别的内存分配。

#2


2  

The int(s) use 4 * 20 bytes. The OpenJDK/Oracle JVM, the header uses 12 bytes, but objects have an 8 byte alignment.

int(s)使用4 * 20字节。 OpenJDK / Oracle JVM,标头使用12个字节,但对象具有8字节对齐。

So the total memory used would be 96 bytes.

所以使用的总内存为96字节。