I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 23e262b0 authored by zzz's avatar zzz
Browse files

* i2psnark: File allocation cleanup to use less heap

parent 47d2b80a
No related branches found
No related tags found
No related merge requests found
...@@ -762,27 +762,19 @@ public class Storage ...@@ -762,27 +762,19 @@ public class Storage
openRAF(nr, false); // RW openRAF(nr, false); // RW
// XXX - Is this the best way to make sure we have enough space for // XXX - Is this the best way to make sure we have enough space for
// the whole file? // the whole file?
long remaining = lengths[nr];
if (listener != null) if (listener != null)
listener.storageCreateFile(this, names[nr], lengths[nr]); listener.storageCreateFile(this, names[nr], remaining);
final int ZEROBLOCKSIZE = piece_size; final int ZEROBLOCKSIZE = (int) Math.min(remaining, 32*1024);
byte[] zeros; byte[] zeros = new byte[ZEROBLOCKSIZE];
try { while (remaining > 0) {
zeros = new byte[ZEROBLOCKSIZE]; int size = (int) Math.min(remaining, ZEROBLOCKSIZE);
} catch (OutOfMemoryError oom) { rafs[nr].write(zeros, 0, size);
throw new IOException(oom.toString()); remaining -= size;
} }
int i;
for (i = 0; i < lengths[nr]/ZEROBLOCKSIZE; i++)
{
rafs[nr].write(zeros);
if (listener != null)
listener.storageAllocated(this, ZEROBLOCKSIZE);
}
int size = (int)(lengths[nr] - i*ZEROBLOCKSIZE);
rafs[nr].write(zeros, 0, size);
// caller will close rafs[nr] // caller will close rafs[nr]
if (listener != null) if (listener != null)
listener.storageAllocated(this, size); listener.storageAllocated(this, lengths[nr]);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment