简体   繁体   English

包装类的空间复杂度

[英]space complexity of wrapper classes

So I'm working on a presentation where I'm trying to show how much more effective a certain program would be if we were to use primitive types instead of wrapper classes, and I'm trying to find the space complexity of different wrappers and how many bytes are being used for which tasks. 因此,我正在一个演示文稿上,尝试显示如果使用原始类型而不是包装器类,则某个程序会更有效,并且我尝试查找不同包装器和多少字节用于哪些任务。 Can someone help me figure out how many bytes are being used for what in an Integer or a Double? 有人可以帮我弄清楚整数或双精度中使用了多少字节吗?

Thanks! 谢谢!

So the answer to this is that an Integer is 16 bytes. 因此,答案是整数为16个字节。 Essentially every object in Java requires 8 bytes of header room for the pointer (reference, etc.), 4 bytes go to the actual int data, and 4 bytes go to "padding" 本质上,Java中的每个对象都需要8个字节的头空间用于指针(引用等),4个字节用于实际的int数据,4个字节用于“填充”

source: Integer vs int: with regard to memory 资料来源: 整数与整数:关于记忆

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

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