diff --git a/README.md b/README.md
index 735f915..7085d0c 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
LArray
===
-A library for managing large off-heap arrays that can hold more than 2G (2^31) entries in Java and Scala.
+A library for managing large off-heap arrays that can hold more than 2G (2^31) entries in Java and Scala. Notably LArray is *disposable* by calling `LArray.free` or you can let GC automatically release the memory. LArray also can be used to create an `mmap` (memory-mapped file) whose size is more than 2GB.
## Features
* LArray can create arrays with more than 2G(2^31) entries.
@@ -94,6 +94,7 @@ A standard JVM, (e.g. Oracle JVM (standard JVM, HotSpotVM) or OpenJDK) must be u
## History
+ * November 11, 2013 version 0.2.1 - Use orgnization name `org.xerial.larray`. Add LBuffer.view.
* November 11, 2013 version 0.2 - Extracted pure-java modules (larray-buffer.jar and larray-mmap.jar) from larray.jar (for Scala).
* August 28, 2013 version 0.1.2 - improved memory layout
* August 28, 2013 version 0.1.1 (for Scala 2.10.2)
@@ -105,7 +106,7 @@ A standard JVM, (e.g. Oracle JVM (standard JVM, HotSpotVM) or OpenJDK) must be u
Add the following sbt dependency to your project settings:
```scala
-libraryDependencies += "org.xerial" % "larray" % "0.2"
+libraryDependencies += "org.xerial.larray" % "larray" % "0.2.1"
```
* Using snapshot versions:
@@ -113,7 +114,7 @@ libraryDependencies += "org.xerial" % "larray" % "0.2"
```scala
resolvers += "Sonatype shapshot repo" at "https://oss.sonatype.org/content/repositories/snapshots/"
-libraryDependencies += "org.xerial" % "larray" % "0.2-SNAPSHOT"
+libraryDependencies += "org.xerial.larray" % "larray" % "0.2.2-SNAPSHOT"
```
### Example
@@ -137,16 +138,16 @@ l2.free
l2(0) // The result of accessing released LArray is undefined
```
-For more examples, see [xerial/larray/example/LArrayExample.scala](larray-scala/src/main/scala/xerial/larray/example/LArrayExample.scala)
+For more examples, see [xerial/larray/example/LArrayExample.scala](larray/src/main/scala/xerial/larray/example/LArrayExample.scala)
## Usage (Java)
Add the following dependency to your pom.xml (Maven):
```xml
- org.xerial
+ org.xerial.larray
larray
- 0.2
+ 0.2.1
```
@@ -165,11 +166,11 @@ int e0 = l.apply(0L); // Get l[0L]
// release
l.free();
```
-For more examples, see [xerial/larray/example/LArrayJavaExample.scala](larray-scala/src/main/scala/xerial/larray/example/LArrayJavaExample.java)
+For more examples, see [xerial/larray/example/LArrayJavaExample.scala](larray/src/main/scala/xerial/larray/example/LArrayJavaExample.java)
## Scaladoc
- * [LArray Scala API](https://oss.sonatype.org/service/local/repositories/releases/archive/org/xerial/larray/0.2/larray-0.2-javadoc.jar/!/index.html#xerial.larray.package)
+ * [LArray Scala API](https://oss.sonatype.org/service/local/repositories/releases/archive/org/xerial/larray/larray/0.2.1/larray-0.2.1-javadoc.jar/!/index.html#xerial.larray.package)
## For developers
diff --git a/larray-buffer/src/main/java/xerial/larray/buffer/BufferConfig.java b/larray-buffer/src/main/java/xerial/larray/buffer/BufferConfig.java
deleted file mode 100644
index d510989..0000000
--- a/larray-buffer/src/main/java/xerial/larray/buffer/BufferConfig.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package xerial.larray.buffer;
-
-/**
- * @author Taro L. Saito
- */
-public class BufferConfig {
-
- public static MemoryAllocator allocator = new OffHeapMemoryAllocator();
-}
diff --git a/larray-buffer/src/main/java/xerial/larray/buffer/OffHeapMemoryAllocator.java b/larray-buffer/src/main/java/xerial/larray/buffer/DefaultMemoryAllocator.java
similarity index 56%
rename from larray-buffer/src/main/java/xerial/larray/buffer/OffHeapMemoryAllocator.java
rename to larray-buffer/src/main/java/xerial/larray/buffer/DefaultMemoryAllocator.java
index fb94e56..a6d3662 100644
--- a/larray-buffer/src/main/java/xerial/larray/buffer/OffHeapMemoryAllocator.java
+++ b/larray-buffer/src/main/java/xerial/larray/buffer/DefaultMemoryAllocator.java
@@ -1,112 +1,33 @@
package xerial.larray.buffer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
+import org.xerial.util.log.Logger;
import java.lang.ref.ReferenceQueue;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
-import static xerial.larray.buffer.UnsafeUtil.unsafe;
-
-
-/**
- * Stores |(memory size:long)| data ... |
- */
-class OffHeapMemory implements Memory {
-
- private final long _data;
-
- public static long HEADER_SIZE = 8L;
-
- /**
- * Create an empty memory
- */
- public OffHeapMemory() {
- this._data = 0L;
- }
-
- public OffHeapMemory(long address) {
- if(address != 0L)
- this._data = address + HEADER_SIZE;
- else
- this._data = 0L;
- }
-
- public OffHeapMemory(long address, long size) {
- if(address != 0L) {
- this._data = address + HEADER_SIZE;
- unsafe.putLong(address, size);
- }
- else {
- this._data = 0L;
- }
- }
-
- public long headerAddress() {
- return _data - HEADER_SIZE;
- }
- public long size() {
- return (_data == 0) ? 0L : unsafe.getLong(headerAddress()) + HEADER_SIZE;
- }
-
- public long address() {
- return _data;
- }
-
- public long dataSize() {
- return (_data == 0) ? 0L : unsafe.getLong(headerAddress());
- }
-
- public MemoryReference toRef(ReferenceQueue queue) {
- return new OffHeapMemoryReference(this, queue);
- }
-
- public void release() {
- if(_data != 0)
- UnsafeUtil.unsafe.freeMemory(headerAddress());
- }
-}
-
-class OffHeapMemoryReference extends MemoryReference {
-
- /**
- * Create a phantom reference
- * @param m the allocated memory
- * @param queue the reference queue to which GCed reference of the Memory will be inserted
- */
- public OffHeapMemoryReference(Memory m, ReferenceQueue queue) {
- super(m, queue);
- }
-
- public Memory toMemory() {
- if(address != 0)
- return new OffHeapMemory(address);
- else
- return new OffHeapMemory();
- }
-
- public String name() { return "off-heap"; }
-
-}
-
/**
- * Allocating off-heap memory
+ * A default implementation of MemoryAllocator that allocates off-heap memory and releases allocated memories in a background thread.
*
* @author Taro L. Saito
*/
-public class OffHeapMemoryAllocator implements MemoryAllocator {
+public class DefaultMemoryAllocator implements MemoryAllocator {
+
+ private Logger logger = Logger.getLogger(DefaultMemoryAllocator.class);
- private Logger logger = LoggerFactory.getLogger(OffHeapMemoryAllocator.class);
// Table from address -> MemoryReference
private Map allocatedMemoryReferences = new ConcurrentHashMap();
private ReferenceQueue queue = new ReferenceQueue();
{
+ // Enable ANSI Color
+ logger.enableColor(true);
+
// Start OffHeapMemory collector that releases the allocated memory when the corresponding Memory object is collected by GC.
Thread collector = new Thread(new Runnable() {
@Override
@@ -136,15 +57,19 @@ public void run() {
*/
public long allocatedSize() { return totalAllocatedSize.get(); }
+ /**
+ * Allocate a memory of the specified byte length. The allocated memory must be released via `release`
+ * as in malloc() in C/C++.
+ * @param size byte length of the memory
+ * @return allocated memory information
+ */
public Memory allocate(long size) {
if(size == 0L)
- return new OffHeapMemory();
+ return new OffHeapMemory();
// Allocate memory of the given size + HEADER space
long memorySize = size + OffHeapMemory.HEADER_SIZE;
- long address = unsafe.allocateMemory(memorySize);
- if(logger.isTraceEnabled())
- logger.trace(String.format("Allocated memory address:%x, size:%,d", address, size));
+ long address = UnsafeUtil.unsafe.allocateMemory(memorySize);
Memory m = new OffHeapMemory(address, size);
register(m);
return m;
@@ -183,10 +108,9 @@ public void release(Memory m) {
synchronized(this) {
long address = m.headerAddress();
if(allocatedMemoryReferences.containsKey(address)) {
- long size = m.size();
if(logger.isTraceEnabled())
- logger.trace(String.format("Released memory address:%x, size:%,d", address, size));
- totalAllocatedSize.getAndAdd(-size);
+ logger.trace(String.format("Released memory address:%x, size:%,d", address, m.dataSize()));
+ totalAllocatedSize.getAndAdd(-m.size());
allocatedMemoryReferences.remove(address);
m.release();
}
diff --git a/larray-buffer/src/main/java/xerial/larray/buffer/LBuffer.java b/larray-buffer/src/main/java/xerial/larray/buffer/LBuffer.java
index 24aa1c1..f2c310d 100644
--- a/larray-buffer/src/main/java/xerial/larray/buffer/LBuffer.java
+++ b/larray-buffer/src/main/java/xerial/larray/buffer/LBuffer.java
@@ -14,7 +14,7 @@ public class LBuffer extends LBufferAPI {
* @param size byte size of the array
*/
public LBuffer(long size) {
- super(BufferConfig.allocator.allocate(size));
+ super(LBufferConfig.allocator.allocate(size));
}
diff --git a/larray-buffer/src/main/java/xerial/larray/buffer/LBufferAPI.java b/larray-buffer/src/main/java/xerial/larray/buffer/LBufferAPI.java
index 0e72ecb..da51d71 100644
--- a/larray-buffer/src/main/java/xerial/larray/buffer/LBufferAPI.java
+++ b/larray-buffer/src/main/java/xerial/larray/buffer/LBufferAPI.java
@@ -21,6 +21,7 @@ public class LBufferAPI {
public LBufferAPI() {
}
+
public LBufferAPI(Memory m) {
this.m = m;
}
@@ -71,7 +72,7 @@ public void update(long offset, byte value) {
* getXXX and putXXX methods becomes undefined.
*/
public void release() {
- BufferConfig.allocator.release(m);
+ LBufferConfig.allocator.release(m);
m = null;
}
@@ -85,14 +86,27 @@ public long address() {
return m.address();
}
+ /**
+ * Size of this buffer
+ * @return
+ */
public long size() {
return m.dataSize();
}
+ /**
+ * Clear the buffer by filling with zeros
+ */
public void clear() {
fill(0, size(), (byte) 0);
}
+ /**
+ * Fill the buffer of the specified range with a given value
+ * @param offset
+ * @param length
+ * @param value
+ */
public void fill(long offset, long length, byte value) {
unsafe.setMemory(address() + offset, length, value);
}
@@ -210,6 +224,13 @@ public void putDouble(long offset, double value) {
}
+ /**
+ * Copy the contents of this buffer begginning from the srcOffset to a destination byte array
+ * @param srcOffset
+ * @param destArray
+ * @param destOffset
+ * @param size
+ */
public void copyTo(int srcOffset, byte[] destArray, int destOffset, int size) {
int cursor = destOffset;
for (ByteBuffer bb : toDirectByteBuffers(srcOffset, size)) {
@@ -221,10 +242,23 @@ public void copyTo(int srcOffset, byte[] destArray, int destOffset, int size) {
}
}
- public void copyTo(long srcOffset, LBuffer dest, long destOffset, long size) {
+ /**
+ * Copy the contents of this buffer to the destination LBuffer
+ * @param srcOffset
+ * @param dest
+ * @param destOffset
+ * @param size
+ */
+ public void copyTo(long srcOffset, LBufferAPI dest, long destOffset, long size) {
unsafe.copyMemory(address() + srcOffset, dest.address() + destOffset, size);
}
+ /**
+ * Extract a slice [from, to) of this buffer. This methods creates a copy of the specified region.
+ * @param from
+ * @param to
+ * @return
+ */
public LBuffer slice(long from, long to) {
if(from > to)
throw new IllegalArgumentException(String.format("invalid range %,d to %,d", from, to));
@@ -235,6 +269,24 @@ public LBuffer slice(long from, long to) {
return b;
}
+ /**
+ * Create a view of the range [from, to) of this buffer. Unlike slice(from, to), the generated view
+ * is a reference to this buffer.
+ * @param from
+ * @param to
+ * @return
+ */
+ public WrappedLBuffer view(long from, long to) {
+ if(from > to)
+ throw new IllegalArgumentException(String.format("invalid range %,d to %,d", from, to));
+
+ return new WrappedLBuffer(m, from, to - from);
+ }
+
+ /**
+ * Convert this buffer to a java array.
+ * @return
+ */
public byte[] toArray() {
if (size() > Integer.MAX_VALUE)
throw new IllegalStateException("Cannot create byte array of more than 2GB");
@@ -247,10 +299,21 @@ public byte[] toArray() {
return b;
}
+ /**
+ * Write the buffer contents to the given file channel. This method just
+ * calls channel.write(this.toDirectByteBuffers());
+ * @param channel
+ * @throws IOException
+ */
public void writeTo(FileChannel channel) throws IOException {
channel.write(toDirectByteBuffers());
}
+ /**
+ * Dump the buffer contents to a file
+ * @param file
+ * @throws IOException
+ */
public void writeTo(File file) throws IOException {
FileChannel channel = new FileOutputStream(file).getChannel();
try {
@@ -260,10 +323,24 @@ public void writeTo(File file) throws IOException {
}
}
+ /**
+ * Read the given source byte array, then overwrite the buffer contents
+ * @param src
+ * @param destOffset
+ * @return
+ */
public int readFrom(byte[] src, long destOffset) {
return readFrom(src, 0, destOffset, src.length);
}
+ /**
+ * Read the given source byte arrey, then overwrite the buffer contents
+ * @param src
+ * @param srcOffset
+ * @param destOffset
+ * @param length
+ * @return
+ */
public int readFrom(byte[] src, int srcOffset, long destOffset, int length) {
int readLen = (int) Math.min(src.length - srcOffset, Math.min(size() - destOffset, length));
ByteBuffer b = toDirectByteBuffer(destOffset, readLen);
@@ -273,6 +350,12 @@ public int readFrom(byte[] src, int srcOffset, long destOffset, int length) {
}
+ /**
+ * Create an LBuffer from a given file.
+ * @param file
+ * @return
+ * @throws IOException
+ */
public static LBuffer loadFrom(File file) throws IOException {
FileChannel fin = new FileInputStream(file).getChannel();
long fileSize = fin.size();
@@ -288,10 +371,20 @@ public static LBuffer loadFrom(File file) throws IOException {
}
+ /**
+ * Gives an sequence of ByteBuffers. Writing to these ByteBuffers modifies the contents of this LBuffer.
+ * @return
+ */
public ByteBuffer[] toDirectByteBuffers() {
return toDirectByteBuffers(0, size());
}
+ /**
+ * Gives an sequence of ByteBuffers of a specified range. Writing to these ByteBuffers modifies the contents of this LBuffer.
+ * @param offset
+ * @param size
+ * @return
+ */
public ByteBuffer[] toDirectByteBuffers(long offset, long size) {
long pos = offset;
long blockSize = Integer.MAX_VALUE;
@@ -308,6 +401,12 @@ public ByteBuffer[] toDirectByteBuffers(long offset, long size) {
}
+ /**
+ * Gives a ByteBuffer view of the specified range. Writing to the returned ByteBuffer modifies the contenets of this LByteBuffer
+ * @param offset
+ * @param size
+ * @return
+ */
public ByteBuffer toDirectByteBuffer(long offset, int size) {
return UnsafeUtil.newDirectByteBuffer(address() + offset, size);
}
diff --git a/larray-buffer/src/main/java/xerial/larray/buffer/LBufferConfig.java b/larray-buffer/src/main/java/xerial/larray/buffer/LBufferConfig.java
new file mode 100644
index 0000000..2ee7441
--- /dev/null
+++ b/larray-buffer/src/main/java/xerial/larray/buffer/LBufferConfig.java
@@ -0,0 +1,10 @@
+package xerial.larray.buffer;
+
+/**
+ * Holding the default memory allocator
+ * @author Taro L. Saito
+ */
+public class LBufferConfig {
+
+ public static MemoryAllocator allocator = new DefaultMemoryAllocator();
+}
diff --git a/larray-buffer/src/main/java/xerial/larray/buffer/MemoryAllocator.java b/larray-buffer/src/main/java/xerial/larray/buffer/MemoryAllocator.java
index 472d0dd..0b4ddd2 100644
--- a/larray-buffer/src/main/java/xerial/larray/buffer/MemoryAllocator.java
+++ b/larray-buffer/src/main/java/xerial/larray/buffer/MemoryAllocator.java
@@ -14,15 +14,19 @@ public interface MemoryAllocator {
*/
Memory allocate(long size);
+ /**
+ * Register a memory
+ * @param m
+ */
void register(Memory m);
/**
- * Release the memory allocated by allocate(size).
+ * Release a memory
*/
void release(Memory m);
/**
- * Release the memory allocated by allocate(size).
+ * Release a memory, referenced by ref
*/
void release(MemoryReference ref);
diff --git a/larray-buffer/src/main/java/xerial/larray/buffer/OffHeapMemory.java b/larray-buffer/src/main/java/xerial/larray/buffer/OffHeapMemory.java
new file mode 100644
index 0000000..b9bad84
--- /dev/null
+++ b/larray-buffer/src/main/java/xerial/larray/buffer/OffHeapMemory.java
@@ -0,0 +1,67 @@
+package xerial.larray.buffer;
+
+import java.lang.ref.ReferenceQueue;
+
+import static xerial.larray.buffer.UnsafeUtil.unsafe;
+
+/**
+ * Stores |(memory size:long)| data ... |
+ */
+public class OffHeapMemory implements Memory {
+
+ private final long _data;
+
+ public static long HEADER_SIZE = 8L;
+
+ /**
+ * Create an empty memory
+ */
+ public OffHeapMemory() {
+ this._data = 0L;
+ }
+
+ public OffHeapMemory(long address) {
+ if(address != 0L)
+ this._data = address + HEADER_SIZE;
+ else
+ this._data = 0L;
+ }
+
+ public OffHeapMemory(long address, long size) {
+ if(address != 0L) {
+ this._data = address + HEADER_SIZE;
+ unsafe.putLong(address, size);
+ }
+ else {
+ this._data = 0L;
+ }
+ }
+
+
+
+ public long headerAddress() {
+ return _data - HEADER_SIZE;
+ }
+ public long size() {
+ return (_data == 0) ? 0L : unsafe.getLong(headerAddress()) + HEADER_SIZE;
+ }
+
+ public long address() {
+ return _data;
+ }
+
+ public long dataSize() {
+ return (_data == 0) ? 0L : unsafe.getLong(headerAddress());
+ }
+
+ public MemoryReference toRef(ReferenceQueue queue) {
+ return new OffHeapMemoryReference(this, queue);
+ }
+
+ public void release() {
+ if(_data != 0)
+ UnsafeUtil.unsafe.freeMemory(headerAddress());
+ }
+}
+
+
diff --git a/larray-buffer/src/main/java/xerial/larray/buffer/OffHeapMemoryReference.java b/larray-buffer/src/main/java/xerial/larray/buffer/OffHeapMemoryReference.java
new file mode 100644
index 0000000..8900e0c
--- /dev/null
+++ b/larray-buffer/src/main/java/xerial/larray/buffer/OffHeapMemoryReference.java
@@ -0,0 +1,28 @@
+package xerial.larray.buffer;
+
+import java.lang.ref.ReferenceQueue;
+
+/**
+ * @author Taro L. Saito
+ */
+public class OffHeapMemoryReference extends MemoryReference {
+
+ /**
+ * Create a phantom reference
+ * @param m the allocated memory
+ * @param queue the reference queue to which GCed reference of the Memory will be inserted
+ */
+ public OffHeapMemoryReference(Memory m, ReferenceQueue queue) {
+ super(m, queue);
+ }
+
+ public Memory toMemory() {
+ if(address != 0)
+ return new OffHeapMemory(address);
+ else
+ return new OffHeapMemory();
+ }
+
+ public String name() { return "off-heap"; }
+
+}
diff --git a/larray-buffer/src/main/java/xerial/larray/buffer/WrappedLBuffer.java b/larray-buffer/src/main/java/xerial/larray/buffer/WrappedLBuffer.java
new file mode 100644
index 0000000..58ba96b
--- /dev/null
+++ b/larray-buffer/src/main/java/xerial/larray/buffer/WrappedLBuffer.java
@@ -0,0 +1,28 @@
+package xerial.larray.buffer;
+
+/**
+ * A subrange of memory
+ *
+ * @author Taro L. Saito
+ */
+public class WrappedLBuffer extends LBufferAPI {
+
+ private final long offset;
+ private final long size;
+
+ public WrappedLBuffer(Memory m, long offset, long size) {
+ super(m);
+ this.offset = offset;
+ this.size = size;
+ }
+
+ @Override
+ public long address() {
+ return m.address() + offset;
+ }
+
+ @Override
+ public long size() {
+ return size;
+ }
+}
diff --git a/larray-buffer/src/test/scala/xerial/larray/buffer/WrappedLBufferTest.scala b/larray-buffer/src/test/scala/xerial/larray/buffer/WrappedLBufferTest.scala
new file mode 100644
index 0000000..5cd8093
--- /dev/null
+++ b/larray-buffer/src/test/scala/xerial/larray/buffer/WrappedLBufferTest.scala
@@ -0,0 +1,34 @@
+//--------------------------------------
+//
+// WrappedLBufferTest.scala
+// Since: 2013/12/11 23:07
+//
+//--------------------------------------
+
+package xerial.larray.buffer
+
+import xerial.larray.LArraySpec
+
+/**
+ * @author Taro L. Saito
+ */
+class WrappedLBufferTest extends LArraySpec {
+
+ "WrappedLBuffer" should {
+
+ "be a subrange of LBuffer" in {
+ val l = new LBuffer(10)
+ for(i <- 0 until l.size().toInt) {
+ l(i) = (10 - i).toByte
+ }
+
+ debug(l.toArray.mkString(", "))
+ val v = l.view(3, 8)
+
+ debug(v.toArray.mkString(", "))
+ v.size() shouldBe 8 - 3
+ v.toArray.zipWithIndex.forall{case (a, i) => a == l(i+3)}
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/larray-mmap/src/main/java/xerial/larray/mmap/MMapBuffer.java b/larray-mmap/src/main/java/xerial/larray/mmap/MMapBuffer.java
index 477ae44..b8f5834 100644
--- a/larray-mmap/src/main/java/xerial/larray/mmap/MMapBuffer.java
+++ b/larray-mmap/src/main/java/xerial/larray/mmap/MMapBuffer.java
@@ -1,7 +1,7 @@
package xerial.larray.mmap;
import sun.misc.SharedSecrets;
-import xerial.larray.buffer.BufferConfig;
+import xerial.larray.buffer.LBufferConfig;
import xerial.larray.buffer.LBufferAPI;
import xerial.larray.buffer.UnsafeUtil;
import xerial.larray.impl.LArrayNative;
@@ -101,7 +101,7 @@ public MMapBuffer(File f, long offset, long size, MMapMode mode) throws IOExcept
}
this.m = new MMapMemory(rawAddr, mapSize);
- BufferConfig.allocator.register(m);
+ LBufferConfig.allocator.register(m);
this.address = rawAddr + pagePosition;
}
diff --git a/larray/src/main/java/xerial/larray/japi/LArrayJ.java b/larray/src/main/java/xerial/larray/japi/LArrayJ.java
index 35e518b..87f40ab 100644
--- a/larray/src/main/java/xerial/larray/japi/LArrayJ.java
+++ b/larray/src/main/java/xerial/larray/japi/LArrayJ.java
@@ -17,7 +17,8 @@
import scala.reflect.ClassTag$;
import xerial.larray.*;
-import xerial.larray.buffer.BufferConfig;
+import xerial.larray.buffer.LBufferConfig;
+import xerial.larray.buffer.MemoryAllocator;
import xerial.larray.mmap.MMapMode;
import java.io.File;
@@ -28,7 +29,7 @@
*/
public class LArrayJ {
- static xerial.larray.buffer.MemoryAllocator defaultAllocator() { return BufferConfig.allocator; }
+ static MemoryAllocator defaultAllocator() { return LBufferConfig.allocator; }
public static MappedLByteArray mmap(File f, MMapMode mode) {
return new MappedLByteArray(f, 0L, f.length(), mode, defaultAllocator());
diff --git a/larray/src/main/scala/xerial/larray/example/LArrayJavaExample.java b/larray/src/main/scala/xerial/larray/example/LArrayJavaExample.java
index e5859ee..0ea9ec7 100644
--- a/larray/src/main/scala/xerial/larray/example/LArrayJavaExample.java
+++ b/larray/src/main/scala/xerial/larray/example/LArrayJavaExample.java
@@ -16,7 +16,11 @@
package xerial.larray.example;
import scala.runtime.AbstractFunction1;
-import xerial.larray.*;
+import xerial.larray.LArray;
+import xerial.larray.LIntArray;
+import xerial.larray.LIntArrayBuilder;
+import xerial.larray.LIterator;
+import xerial.larray.buffer.LBuffer;
import xerial.larray.japi.LArrayJ;
import java.io.File;
@@ -83,6 +87,15 @@ public Object apply(Object v1) {
// Release the memory contents
l.free();
+
+ // Using LBuffer
+ LBuffer lbuf = new LBuffer(1000);
+ lbuf.putInt(0, 10);
+ int ten = lbuf.getInt(0);
+ lbuf.address(); // memory address
+ lbuf.release(); // deallocate the memory
+
+
System.out.println("done.");
}
}
diff --git a/larray/src/main/scala/xerial/larray/package.scala b/larray/src/main/scala/xerial/larray/package.scala
index 2febfa0..f58d60c 100644
--- a/larray/src/main/scala/xerial/larray/package.scala
+++ b/larray/src/main/scala/xerial/larray/package.scala
@@ -16,7 +16,7 @@
package xerial
import reflect.ClassTag
-import xerial.larray.buffer.BufferConfig
+import xerial.larray.buffer.LBufferConfig
/**
* == LArray ==
@@ -48,7 +48,7 @@ import xerial.larray.buffer.BufferConfig
*/
package object larray {
- implicit def defaultAllocator : xerial.larray.buffer.MemoryAllocator = BufferConfig.allocator
+ implicit def defaultAllocator : xerial.larray.buffer.MemoryAllocator = LBufferConfig.allocator
implicit class ConvertArrayToLArray[A : ClassTag](arr:Array[A]) {
diff --git a/project/Build.scala b/project/Build.scala
index 99a924f..457dedd 100755
--- a/project/Build.scala
+++ b/project/Build.scala
@@ -24,7 +24,7 @@ object Build extends sbt.Build {
private val SCALA_VERSION = "2.10.3"
val buildSettings = Defaults.defaultSettings ++ Seq(
- organization := "org.xerial",
+ organization := "org.xerial.larray",
organizationName := "xerial.org",
organizationHomepage := Some(new URL("http://xerial.org")),
publishMavenStyle := true,
@@ -41,6 +41,7 @@ object Build extends sbt.Build {
parallelExecution in Test := false,
javacOptions in Compile ++= Seq("-Xlint:unchecked"),
javacOptions in (Compile, doc) <<= (baseDirectory, version) map { (bd, v) => Seq(
+ "-locale", "en_US",
"-sourcepath", bd.getAbsolutePath,
"-doctitle", s"LArray ${v} API"
)},
@@ -132,7 +133,6 @@ object Build extends sbt.Build {
snappy % "test",
junit,
"org.iq80.snappy" % "snappy" % "0.3" % "test",
-
"com.novocode" % "junit-interface" % "0.10-M2" % "test",
"org.scalatest" % "scalatest_2.10" % "2.0.M5b" % "test",
"org.scalacheck" % "scalacheck_2.10" % "1.10.0" % "test",
@@ -150,9 +150,10 @@ object Build extends sbt.Build {
autoScalaLibrary := false,
libraryDependencies ++= Seq(
"org.scalatest" % "scalatest_2.10" % "2.0.M5b" % "test",
- "org.xerial" % "xerial-core" % "3.2.2" % "test",
- slf4j,
- slf4jSimple % "test"
+ "org.xerial.java" % "xerial-core" % "2.1",
+ "org.xerial" % "xerial-core" % "3.2.2" % "test"
+// slf4j,
+// slf4jSimple % "test"
)
)
)
@@ -163,6 +164,7 @@ object Build extends sbt.Build {
settings = buildSettings ++
Seq(
description := "LArray mmap implementation",
+ autoScalaLibrary := false,
libraryDependencies ++= Seq(
snappy % "test",
junit
diff --git a/version.sbt b/version.sbt
index 7e69a72..43b1414 100755
--- a/version.sbt
+++ b/version.sbt
@@ -1,3 +1,3 @@
-version in ThisBuild := "0.2"
+version in ThisBuild := "0.2.1"