简体   繁体   English

Java:“长”号在内存中占多少?

[英]Java:how much does a “long” number take in memory?

do these two numbers both take equally 8bytes(64bit) in the memory? 这两个数字在内存中同样是8字节(64位)吗? long a=25L long b=3543451651313213232168498L 长a = 25L长b = 3543451651313213232168498L

Yes the size is fixed as per the language specification : 是的,大小是根据语言规范修复的:

The integral types are byte, short, int, and long, whose values are 8-bit, 16-bit, 32-bit and 64-bit signed two's-complement integers, respectively [...]. 整数类型为byte,short,int和long,其值分别为8位,16位,32位和64位二进制补码整数[...]。

long的大小是预定的,它不会根据存储的数量而改变。

长需要8个字节,无论它是否包含零(所有位0)或-1(所有位1)。

是的,原语具有固定的大小,并不依赖于它们包含的值!

Yes, it takes the same amount. 是的,它需要相同的金额。

A long value (even 0L ) takes up 64 bit (or 8 bytes). 长值(甚至0L )占用64位(或8字节)。

Yes both take 8 bytes. 是的,都需要8个字节。 Ask yourself the question how you would differentiate between a 32 bit integer and a 'half full' 64 bit long. 问问自己如何区分32位整数和64位长的“半满”。

Yes, both take equal space. 是的,两者都占有相同的空间。 In Java , primitives are allocated a constant space based on the type of primitive. 在Java中,基元的基本类型为基元分配了一个常量空间。 Objects on the other hand, may take variable amount of space over time. 另一方面,对象可能随着时间的推移而占用不同的空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM