Changeset 23e262b


Ignore:
Timestamp:
Sep 19, 2011 1:46:52 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
35e89b7
Parents:
47d2b80
Message:
  • i2psnark: File allocation cleanup to use less heap
File:
1 edited

Legend:

Unmodified
Added
Removed
  • apps/i2psnark/java/src/org/klomp/snark/Storage.java

    r47d2b80 r23e262b  
    763763    // XXX - Is this the best way to make sure we have enough space for
    764764    // the whole file?
     765    long remaining = lengths[nr];
    765766    if (listener != null)
    766         listener.storageCreateFile(this, names[nr], lengths[nr]);
    767     final int ZEROBLOCKSIZE = piece_size;
    768     byte[] zeros;
    769     try {
    770         zeros = new byte[ZEROBLOCKSIZE];
    771     } catch (OutOfMemoryError oom) {
    772         throw new IOException(oom.toString());
     767        listener.storageCreateFile(this, names[nr], remaining);
     768    final int ZEROBLOCKSIZE = (int) Math.min(remaining, 32*1024);
     769    byte[] zeros = new byte[ZEROBLOCKSIZE];
     770    while (remaining > 0) {
     771        int size = (int) Math.min(remaining, ZEROBLOCKSIZE);
     772        rafs[nr].write(zeros, 0, size);
     773        remaining -= size;
    773774    }
    774     int i;
    775     for (i = 0; i < lengths[nr]/ZEROBLOCKSIZE; i++)
    776       {
    777         rafs[nr].write(zeros);
    778         if (listener != null)
    779           listener.storageAllocated(this, ZEROBLOCKSIZE);
    780       }
    781     int size = (int)(lengths[nr] - i*ZEROBLOCKSIZE);
    782     rafs[nr].write(zeros, 0, size);
    783775    // caller will close rafs[nr]
    784776    if (listener != null)
    785       listener.storageAllocated(this, size);
     777      listener.storageAllocated(this, lengths[nr]);
    786778  }
    787779
Note: See TracChangeset for help on using the changeset viewer.