• list容量限制测试


    电脑硬件条件:



    测试代码:
    Java代码  收藏代码
    1. public static void main(String[] args) {  
    2.         ArrayList<Float> list_str=new ArrayList<Float>();  
    3.         int len=(int) Math.pow(222);  
    4.         System.out.println("运行次数:"+len);  
    5.         for(int i=0;i<len;i++){  
    6.             //String str="a "+i;  
    7.             //list_str.add(str);  
    8. //          int t=i;  
    9. //          Student student=new Student();  
    10. //          student.setId(i);  
    11. //          student.setName("第+"+i);  
    12. //          list_str.add(student);  
    13.             float f=(float)i;  
    14.             list_str.add(f);  
    15.         }  
    16.         for(int j=0;j<len;j++){  
    17.             System.out.println(list_str.get(j)+"    "+j);  
    18.         }  
    19.         System.out.println("运行结束!"+len);  
    20.     }  


    一.String为对象存在list里
        1. 当运行了2的16次方时,程序正确执行
        2. 当运行了2的24次方(16777216)时,程序报outofmemory的内存溢出错误
        3. 当运行了2的18次方(262144)时,程序正常运行
        4. 当运行了2的19次方(524288)时,程序正常运行
        5. 当运行了2的20次方(1048576)时,程序报outofmemory:Java heap space的内存溢出错误,说明堆的空间呗用完了

              运行极限是2的19次方
    二.List存int数据
        Int数据是java的基本数据类型,存在栈空间里
        1. 当运行了2的32次方(2147483647)时,程序报outofmemory:Java heap   space
       2. 当运行了2的24次方(16777216)时,程序报outofmemory:Java heap space
       3. 当运行了2的21次方(2097152)时,程序正确执行

    运行极限是2的21次方
    三.自建对象Student存在list中
        1. 当运行了2的21次方(2097152)时,程序报outofmemory:Java heap space
       2. 当运行了2的20次方(1048576)时,程序报outofmemory:Java heap space
       3. 当运行了2的19次方(524288)时,程序正常运行

    运行极限是2的19次方

    四.List存float数据
        1. 当运行了2的19次方(524288)时,程序正常运行
        2. 当运行了2的21次方(2097152)时,程序正确执行
        3. 当运行了2的22次方(4194304)时,程序报outofmemory:Java heap space

    运行的极限是2的21次方
    五.结论
        要是ArrayList存的是int、float的基本数据类型,其最大的容量是2的21次方,要是存的是纯对象类型,其最大容量是2的19次方,它的限制条件的很大一个是内存问题,就是计算机的堆空间用完了


    http://panlianghui-126-com.iteye.com/blog/1472264


  • 相关阅读:
    给XML文件定义DTD
    详探TextRange对象用execCommand()执行命令
    获取屏幕,浏览器,网页高度宽度
    花点时间搞清top、postop、scrolltop、scrollHeight、offsetHeight
    DataView数据组件
    回调实现无刷新级联下拉框(.net)
    ASP.NET的简单数据绑定
    详探TextRange对象查找与选择
    方维系统常用的jquery库以及各个库的含义
    方维购物分享系统 给店铺品牌加喜欢收藏的功能
  • 原文地址:https://www.cnblogs.com/cuker919/p/4878548.html
Copyright © 2020-2023  润新知