BigInteger 使用了多少空间?

2024-04-25

BigInteger 对象通常使用多少字节的内存?


BigInteger 内部使用int[]来表示您使用的巨大数字。 因此它确实取决于您存储在其中的数字的大小. The int[]如果当前数量不能动态适应,则会增长。

要获取您的字节数BigInteger实例现在使用,您可以利用Instrumentation接口,尤其是getObjectSize(Object) http://docs.oracle.com/javase/7/docs/api/java/lang/instrument/Instrumentation.html#getObjectSize%28java.lang.Object%29.

import java.lang.instrument.Instrumentation;

public class ObjectSizeFetcher {
    private static Instrumentation instrumentation;

    public static void premain(String args, Instrumentation inst) {
        instrumentation = inst;
    }

    public static long getObjectSize(Object o) {
        return instrumentation.getObjectSize(o);
    }
}

为了说服自己,请看一下源代码 http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/math/BigInteger.java,其中写着:

/**
 * The magnitude of this BigInteger, in <i>big-endian</i> order: the
 * zeroth element of this array is the most-significant int of the
 * magnitude.  The magnitude must be "minimal" in that the most-significant
 * int ({@code mag[0]}) must be non-zero.  This is necessary to
 * ensure that there is exactly one representation for each BigInteger
 * value.  Note that this implies that the BigInteger zero has a
 * zero-length mag array.
 */
final int[] mag;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

BigInteger 使用了多少空间? 的相关文章

随机推荐

  • html5在移动设备中自动播放视频

    Auto play is not working without muted attribute when I try to open url in mobile device How to play video without using
  • PreLoader 的多线程 - JavaFX

    我正在开发一个 JavaFX 应用程序 需要在启动主应用程序阶段之前从文件中加载资源 我完成此任务的解决方案是使用 PreLoader 以便用户在加载资源之前无法与应用程序交互 非常标准的东西 我有一个扩展 PreLoader 类的类 该类
  • 有没有办法从 VS2010 中的建模项目生成代码?

    有没有办法从 VS2010 中的建模项目生成代码 看来这个功能即将到来 但 Beta2 中还没有 微软的拉梅什 拉贾戈帕尔回答类似的问题 http social msdn microsoft com Forums en US vstspre
  • 如何将回车符作为字符添加到文件中?

    我想要一个像这样的字符串 blablbabla
  • Flexbox,保持纵横比的方形 div 的响应式网格

    我正在尝试用 div 创建一个 2x2 网格 某些 div 可能包含图像 但它可能会被设置为背景 并带有选项background size cover 这是我创建的笔 http codepen io qarlo pen vLEprq htt
  • 如何使用 Arquillian Weld EE Embedded 测试 EJB 方法调用

    我想测试 EJB 并且想使用 Weld EE Embedded 来测试它 因为我不想为此部署应用程序服务器 这是我的课程 RunWith Arquillian class public class EJBTest Deployment pu
  • 将 Sql Server 与 Django 2.0 结合使用

    我想将 Django 2 0 与旧版 MS SQL Server 数据库一起使用 我能找到的有关使用 Django 与 MS SQL Server 的最新信息是在生产中使用 Sql Server 和 Django 这些天 https sta
  • Java 线程转储:阻塞线程而不“等待锁定...”

    我很难理解从 jstack 获得的 Tomcat 6 java 1 6 0 22 Linux 上运行的 Spring MVC Web 应用程序的线程转储 我看到阻塞线程 导致其他线程等待 本身被阻塞 但是线程转储并没有告诉我原因或它们正在等
  • removeEventListener 的行为

    请检查以下代码 var clickfn function alert clicked document getElementById div1 addEventListener click clickfn true clickfn func
  • Arc4随机模偏置

    根据本文档 https developer apple com library mac documentation darwin reference manpages man3 arc4random 3 html arc4random un
  • ggplot2、geom_bar、闪避、条形顺序

    我想订购道奇酒吧geom bar 你知道如何处理吗 My code ttt lt data frame typ rep c main boks cuk 2 klaster rep c 1 2 3 ile c 5 4 6 1 8 7 ggpl
  • PHP password_hash 检查两个哈希值

    如果我有两个使用创建的密码哈希password hash http www php net manual en function password hash php函数 我如何判断它们是否来自相同的基本密码 我知道它每次都使用不同的盐 我没
  • 如何使用 SDK 3.1 指定用户用于发布的应用程序名称(通过应用程序名称)

    使用新的 Facebook SDK 3 1 和 iOS 6 有 2 种 实际上 3 种 发帖方式 似乎新的趋势是有更多的选择 使其更简单 天哪 这是一个 SLComposeViewController fbPost SLComposeVie
  • C# Windows Phone - xaml ListBox.ItemTemplate 中的对齐方式

    我想做一个简单的列表框 每行应包含 2 个控件 一个左对齐 另一个右对齐 仅此而已 我尝试了多种方法但没有任何效果 我的代码如下
  • 如何用js添加表格?

    我想通过 JavaScript 在我的 html 表格上添加一个表格 我已经尝试过使用appendChild and insertBefore方法 但这些方法都不起作用 这是我的 JavaScript var utilisateur id
  • 二维数组与一维数组

    我已经阅读了这个问题二维数组与一维数组的性能 https stackoverflow com questions 1242705 performance of 2 dimensional array vs 1 dimensional arr
  • 迭代集合元素

    我已经打开了实验性 ECMAscript 6 功能的 Chrome 标志 其中之一是Set 据我了解 详细信息Set得到了规范作者的广泛同意 我创建一个集合a并添加字符串 Hello a Set a add Hello 但我如何迭代的元素a
  • 使用 HTML 页面的 css 格式显示标签导出到 Excel

    我在我的网络应用程序中使用显示标签 我成功地将显示标签显示的数据导出到Excel 问题是我还希望标题和数据行样式以及 css 包含在导出的 Excel 中 例如标题行为粗体 背景为灰色 数据行中的列根据值着色 但这并没有导出到 Excel
  • 我可以重写 C# 中的属性吗?如何?

    我有这个基类 abstract class Base public int x get throw new NotImplementedException 以及以下后代 class Derived Base public int x get
  • BigInteger 使用了多少空间?

    BigInteger 对象通常使用多少字节的内存 BigInteger 内部使用int 来表示您使用的巨大数字 因此它确实取决于您存储在其中的数字的大小 The int 如果当前数量不能动态适应 则会增长 要获取您的字节数BigIntege