길이가 2 억 2 천만 (고정) 인 int 및 float 배열이 있습니다. 자, 메모리/디스크에 /에서 배열을 저장/업로드하고 싶습니다. 현재 Java NIO의 FileChannel 및 MappedByteBuffer를 사용하여이 문제를 해결하고 있습니다. 그것은 잘 동작하지만 메모리를 디스크에 저장/업로드하기 위해 약 5 초 (Wall Clock Time)가 소요됩니다. 사실, 나는 더 빠른 것을 원한다. 아무도 나를 도울 수있는 모든 inbuilt 자바 라이브러리/데이터베이스/업로드/저장소를 훨씬 빨리 저장하는 다른 방법은 무엇입니까? 디스크에서 메모리로 업로드하는 데 특별히주의해야합니다. 나는 그것을 더 빨리 만들고 싶다. 그래서, 저장하는데 시간이 걸리면 아무런 문제가 없습니다. 미리 감사드립니다.Java - 배열 및 메모리에서 디스크로 저장/업로드
내가 (필요한 경우) 아래에 주어진 사용하고 코드 : 전혀 사본을하고 있지 않도록
int savenum = 220000000 ;
public void save() {
try {
long l = 0 ;
FileChannel channel = new RandomAccessFile(str1, "rw").getChannel();
MappedByteBuffer mbb = channel.map(FileChannel.MapMode.READ_WRITE, 0, savenum * 8);
mbb.order(ByteOrder.nativeOrder());
for(int i = 0 ; i < savenum ; i++){
l = a[i] ;
mbb.putLong(l);
}
channel.close();
FileChannel channel1 = new RandomAccessFile(str2, "rw").getChannel();
MappedByteBuffer mbb1 = channel1.map(FileChannel.MapMode.READ_WRITE, 0, savenum * 4);
mbb1.order(ByteOrder.nativeOrder());
for(int i = 0 ; i < savenum ; i++){
int ll = b[i] ;
mbb1.putInt(ll);
}
channel1.close();
}
catch (Exception e){
System.out.println("IOException : " + e);
}
}
public void load(){
try{
FileChannel channel2 = new RandomAccessFile(str1, "r").getChannel();
MappedByteBuffer mbb2 = channel2.map(FileChannel.MapMode.READ_ONLY, 0, channel2.size());
mbb2.order(ByteOrder.nativeOrder());
assert mbb2.remaining() == savenum * 8;
for (int i = 0; i < savenum; i++) {
long l = mbb2.getLong();
a[i] = l ;
}
channel2.close();
FileChannel channel3 = new RandomAccessFile(str2, "r").getChannel();
MappedByteBuffer mbb3 = channel3.map(FileChannel.MapMode.READ_ONLY, 0, channel3.size());
mbb3.order(ByteOrder.nativeOrder());
assert mbb3.remaining() == savenum * 4;
for (int i = 0; i < savenum; i++) {
int l1 = mbb3.getInt();
b[i] = l1 ;
}
channel3.close();
}
catch(Exception e){
System.out.println(e) ;
}
}
440 만 항목의 경우 5 초가 꽤 좋은 것처럼 들립니다. –
@HunterMcMillen, 나는 더 빨리 원한다. :). – Arpssss
파일이 디스크에 얼마나 큽니까? 나는 헌터와 동의하는 경향이있다. 시간은 나에게 꽤 좋다. 분명히 디스크 성능을 향상시키기 위해 컴퓨터를 업그레이드 할 수 있습니까? SSD가 쓰기에 도움이되는지 확신하지 못합니까? – davidfrancis