zoukankan      html  css  js  c++  java
  • 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


  • 相关阅读:
    apache commons-io相关介绍-IOUtils类
    apache commons-io相关介绍-DirectoryWalker类
    apache commons-io相关介绍-FileUtils类
    apache commons-io相关介绍-monitor包
    android笔记--AsyncTask例子
    Java Swing中的SwingWorker
    Predicting Boston Housing Prices
    matplotlib.pyplot 中很好看的一种style
    机器学习算法比较
    udacity 机器学习课程 project2
  • 原文地址:https://www.cnblogs.com/cuker919/p/4878548.html
Copyright © 2011-2022 走看看