lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bmes...@apache.org
Subject svn commit: r351779 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/store/RAMDirectory.java
Date Fri, 02 Dec 2005 17:38:12 GMT
Author: bmesser
Date: Fri Dec  2 09:37:50 2005
New Revision: 351779

URL: http://svn.apache.org/viewcvs?rev=351779&view=rev
Log:
LUCENE-475 - patch from Volodymyr Bychkoviak to reduce memory usage
when loading an index into RAMDirectory.

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/store/RAMDirectory.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/CHANGES.txt?rev=351779&r1=351778&r2=351779&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Fri Dec  2 09:37:50 2005
@@ -304,7 +304,10 @@
 17. A single hit using the expert level sorted search methods
     resulted in the score not being normalized.
     (Yonik Seeley, LUCENE-462)
-	
+
+18. Fixed inefficient memory usage when loading an index into RAMDirectory.
+	(Volodymyr Bychkoviak via Bernhard, LUCENE-475)
+		
 Optimizations
      
  1. Disk usage (peak requirements during indexing and optimization)

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/RAMDirectory.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/store/RAMDirectory.java?rev=351779&r1=351778&r2=351779&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/RAMDirectory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/RAMDirectory.java Fri Dec  2 09:37:50
2005
@@ -53,6 +53,7 @@
   
   private RAMDirectory(Directory dir, boolean closeDir) throws IOException {
     final String[] files = dir.list();
+    byte[] buf = new byte[BufferedIndexOutput.BUFFER_SIZE];
     for (int i = 0; i < files.length; i++) {
       // make place on ram disk
       IndexOutput os = createOutput(files[i]);
@@ -60,9 +61,14 @@
       IndexInput is = dir.openInput(files[i]);
       // and copy to ram disk
       int len = (int) is.length();
-      byte[] buf = new byte[len];
-      is.readBytes(buf, 0, len);
-      os.writeBytes(buf, len);
+      int readCount = 0;
+      while (readCount < len) {
+        int toRead = readCount + BufferedIndexOutput.BUFFER_SIZE > len ? len - readCount
: BufferedIndexOutput.BUFFER_SIZE;
+        is.readBytes(buf, 0, toRead);
+        os.writeBytes(buf, toRead);
+        readCount += toRead;
+      }
+
       // graceful cleanup
       is.close();
       os.close();



Mime
View raw message