问题描述
如何在C ++中计算new BitSet(n)
的内存.
How to compute the memory of new BitSet(n)
in C++.
内存占用了new BitSet(1024)
在Java中.
What memory takes the new BitSet(1024)
in Java.
但是Java的公式似乎有所不同.我想计算用于new BitSet(100000)
的内存,请您帮忙?
But it seems the formula for Java is different. I want to compute the memory spent for new BitSet(100000)
, could you please help?
推荐答案
BitSet被打包到单词"数组中.一个单词(在当前实现中)很长.内部的单个位将被检索/使用掩码进行设置;因此,它在内部将64位压缩为一个long值,并使用long数组来容纳所需的所有位.
BitSet are packed into arrays of "words." A word is (in the current implementation) a long. The single bits inside will be retrieved / set uses masking; therefore it internally packs 64 bits in one single long value, and uses an array of longs to hold all the bits you need.
数组的大小将为N(100000)/64字节,即1563长,即12504字节,再加上BitSet用于其内部结构/布告的固定开销.
The dimension of the array will be N (100000) / 64 bytes, or 1563 longs, or 12504 bytes, plus a fixed overhead needed by BitSet for its internal structure/bookeeping.
请参见 http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/util/BitSet.java ;计算字段并总结所需的空间(一个int:4个字节;一个long:8个字节,依此类推),您可以了解固定开销是多少.
See http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/util/BitSet.java for the implementation; counting the fields and summing up the space they need (an int: 4 bytes; a long: 8 bytes, and so on) you can understand how much is the fixed overhead.
这篇关于Java 32位系统BitSet的内存大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!