class 1:
package ruc.datasearch.signature;public class CandidateDataType {
public Integer L_ID;
public Integer R_ID;
public CandidateDataType()
{
this.L_ID=-1;
this.R_ID=-1;
}

public CandidateDataType(int L_ID,int R_ID)
{
this.L_ID=L_ID;
this.R_ID=R_ID;
}
}
class 2:
package ruc.datasearch.signature;import java.util.ArrayList;public class Candidate {
private List<CandidateDataType> candList;
        public Candidate()
{
candList=new ArrayList<CandidateDataType>();
} public void add()
{
        for(int i=0;i<70026614;i++)
{
list.add(new CandidateDataType(i,i));
}
System.out.print(list.size());
}
当调用类 Candidate的add方法之后,由于i值较大,导致内存溢出。
鉴于这种情况使用何种方法来存储(int,int)这样类型的数据呢?希望大家不吝赐教,有任何idea都可以说。
谢谢!(要求:i值很大,没法减少了;只能全部存储在内存中,不能存储在外存)

解决方案 »

  1.   

    加大JVM虚拟内存...
    Integer内存占用貌似比int大 可以用int变量
    如果可以的话 用short代替int..
      

  2.   

    JVM虚拟内存现在用到1G了,再大机器不行了,呵呵。
    int的话也是不可以,我单独用int测试过。
    有没有其它的方法来存储?
      

  3.   

    int怎么存List里?
    short够70026614么?这个结构我觉得用一个二维数组足矣。
      

  4.   


    新问题是,如果用二维数组的话,我不知道i值得大小,如何办呢?(java不支持动态数组吧?)
      

  5.   


        不好意思 有点想当然了=-= 
        我再随便扯点哈,表喷我...
        我觉得吧 想要在存储量上有提升,效率上或许就要有降低,你是不是需要采取某些办法压缩数据...比如用压缩算法..囧
        我再举个比较CUO的例子,比如你的数据范围仅限整数并且保证小于9999,那么你的List只需要存一个Integer,1-4位是R_ID,5-8位是L_ID
        不要喷我不要喷我... >_<
      

  6.   

    java有很多动态数组,ArrayList,LinkedList等,参考手册java.util 。
      

  7.   

    [ list.add(new CandidateDataType(i,i));---list其实是不是candList?]list.add(new CandidateDataType(i,i)) 用两个Hashtable(或HashMap)就行:
       Hashtable<Integer, String> numbers = new Hashtable<Integer, String>();
       numbers.put(i, CandidateDataType.L_ID);
       numbers.put(i, CandidateDataType.R_ID);ps: i值较大,JAVA的Long还没用呢,况且还有BigInteger。
      

  8.   

    [ list.add(new CandidateDataType(i,i));---list其实是不是candList?]list.add(new CandidateDataType(i,i)) 用两个Hashtable(或HashMap)就行:
      Hashtable<Integer, String> numbers = new Hashtable<Integer, String>();
      numbers.put(i, CandidateDataType.L_ID);
      numbers.put(i, CandidateDataType.R_ID);
      

  9.   

    CSDN 不能编辑、删除自己的帖子,麻烦!(没有足够的权限)list.add(new CandidateDataType(i,i)) 用一、或两个Hashtable:  Hashtable<Integer, Integer> numbers = new Hashtable<Integer, Integer>();
      numbers.put(i, i);
    或:
      Hashtable<Integer, String> number1 = new Hashtable<Integer, String>();
      Hashtable<Integer, String> number2 = new Hashtable<Integer, String>();
      number1.put(i, CandidateDataType.L_ID);
      number2.put(i, CandidateDataType.R_ID);
      

  10.   

      查了查资料,理论上来说 list和hashmap数据条是可以无限放的。。只要你的JVM的内存够。但这只是理论上,既然内存溢出了,一个list与多个list会是一样溢出的,这只能分段来处理了,70026614分段,每次30万,或300万。
      另外,可尝试修改虚拟机默认内存,就是运行时-XmxXXXm。使用带容量参数的构造方法,如ArrayList<E> al=new ArrayList<E>(300000); 
      

  11.   

    JVM内存已经不能再往大扩展了。
    bayougeng所提出的二维数组的方法还是不错的,但是问题是不能动态增长。像ArrayList和LinkedList肯定是不行的,这种结构所占空间较大,像例子中这样的i值就把内存撑爆了。二维数组在1GJVM内存里倒是可以放得下这些东西。P.S. 例子中的list写错了,不好意思,其实就是candList。谢谢大家的帮助,我酌情给分吧。感谢!
      

  12.   

    最后我是这样解决的。用HashMap,将相同L_ID的值作为key,value用的List<Integer>,一定程度上的压缩吧。
    数据结构如下:
    private Map<Integer,List<Integer>> store=new HashMap<Integer,List<Integer>>();
    希望对大家有所帮助,谢谢!