Update
diff --git a/.gitignore b/.gitignore
index f617d02..9ec3e63 100644
--- a/.gitignore
+++ b/.gitignore
@@ -63,3 +63,4 @@
_site/
_*
_*/
+deps/
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java
index dcee60c..4ef5f68 100644
--- a/src/main/java/module-info.java
+++ b/src/main/java/module-info.java
@@ -22,7 +22,7 @@
* @author lrhodes
*
*/
-module org.apache.datasketches.memory {
+module org.apache.datasketches.memseg {
requires jdk.incubator.foreign;
- exports org.apache.datasketches.memory;
+ exports org.apache.datasketches.memseg;
}
diff --git a/src/main/java/org/apache/datasketches/memory/AllocateDirect.java b/src/main/java/org/apache/datasketches/memseg/AllocateDirect.java
similarity index 65%
rename from src/main/java/org/apache/datasketches/memory/AllocateDirect.java
rename to src/main/java/org/apache/datasketches/memseg/AllocateDirect.java
index ab564d0..d4a744c 100644
--- a/src/main/java/org/apache/datasketches/memory/AllocateDirect.java
+++ b/src/main/java/org/apache/datasketches/memseg/AllocateDirect.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.datasketches.memory;
+package org.apache.datasketches.memseg;
//import jdk.incubator.foreign.MemoryAddress;
import jdk.incubator.foreign.MemorySegment;
@@ -28,15 +28,19 @@
*
* @author Lee Rhodes
*/
-class AllocateDirect {
+final class AllocateDirect implements AutoCloseable {
private final MemorySegment directSeg;
/**
- * Construct Memory Segment
- * @param capacityBytes blah
+ * Base Constructor for allocate native memory.
+ *
+ * <p>Allocates and provides access to capacityBytes directly in native (off-heap) memory
+ * leveraging the Memory interface.
+ * The allocated memory will be 8-byte aligned, but may not be page aligned.
+ * @param capacityBytes the the requested capacity of off-heap memory. Cannot be zero.
*/
AllocateDirect(final long capacityBytes) {
- directSeg = MemorySegment.allocateNative(capacityBytes);
+ directSeg = MemorySegment.allocateNative(capacityBytes, 8);
}
MemorySegment getMemorySegment() {
@@ -47,23 +51,12 @@
return directSeg.address().toRawLongValue();
}
- void close() {
+ @Override
+ public void close() {
directSeg.close();
}
+
+
- @SuppressWarnings("resource")
- public static void checkAllocDirect() {
- final long bytesIn = 64;
- AllocateDirect allocateDirect = new AllocateDirect(bytesIn);
- final MemorySegment seg = allocateDirect.getMemorySegment();
- final long bytesOut = seg.byteSize();
- String out = (bytesOut == bytesIn) ? "OK" : "Not OK";
- System.out.println(out);
- allocateDirect.close();
- }
-
- public static void main(final String[] args) {
- checkAllocDirect();
- }
}
diff --git a/src/main/java/org/apache/datasketches/memseg/package-info.java b/src/main/java/org/apache/datasketches/memseg/package-info.java
new file mode 100644
index 0000000..4faf9db
--- /dev/null
+++ b/src/main/java/org/apache/datasketches/memseg/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * @author lrhodes
+ */
+package org.apache.datasketches.memseg;
diff --git a/src/test/java/org/apache/datasketches/memory/AllocateDirectTest.java b/src/test/java/org/apache/datasketches/memseg/AllocateDirectTest.java
similarity index 68%
rename from src/test/java/org/apache/datasketches/memory/AllocateDirectTest.java
rename to src/test/java/org/apache/datasketches/memseg/AllocateDirectTest.java
index 1d03488..352dc4a 100644
--- a/src/test/java/org/apache/datasketches/memory/AllocateDirectTest.java
+++ b/src/test/java/org/apache/datasketches/memseg/AllocateDirectTest.java
@@ -17,11 +17,14 @@
* under the License.
*/
-package org.apache.datasketches.memory;
+package org.apache.datasketches.memseg;
+
+import static org.testng.Assert.assertEquals;
+
+import org.testng.annotations.Test;
import jdk.incubator.foreign.MemorySegment;
-import org.testng.annotations.Test;
-//import static org.testng.Assert.assertEquals;
+
/**
@@ -32,20 +35,21 @@
*/
public class AllocateDirectTest {
- /**
- * check AllocDirect.
- */
@Test
@SuppressWarnings("resource")
public void checkAllocDirect() {
final long bytesIn = 64;
- AllocateDirect allocateDirect = new AllocateDirect(bytesIn);
- final MemorySegment seg = allocateDirect.getMemorySegment();
- final long bytesOut = seg.byteSize();
- String out = (bytesOut == bytesIn) ? "OK" : "Not OK";
- System.out.println(out);
- allocateDirect.close();
+ try (AllocateDirect allocateDirect = new AllocateDirect(bytesIn)) {
+ final MemorySegment seg = allocateDirect.getMemorySegment();
+ final long bytesOut = seg.byteSize();
+ assertEquals(bytesOut, bytesIn);
+ String str = (bytesOut == bytesIn) ? "OK" : "Not OK";
+ println(str);
+ //allocateDirect.close(); //fast close
+ }
}
+
+ static void println(Object o) { System.out.println(o.toString()); }
}
diff --git a/tools/MemoryCheckstyle.xml b/tools/MemoryCheckstyle.xml
index 3b80313..727ac63 100644
--- a/tools/MemoryCheckstyle.xml
+++ b/tools/MemoryCheckstyle.xml
@@ -126,7 +126,7 @@
<module name="JavadocParagraph"/>
<module name="JavadocTagContinuationIndentation">
<property name="severity" value="ignore"/>
- <metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
+ <!-- <metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/> -->
</module>
<module name="NonEmptyAtclauseDescription"/>
<module name="SingleLineJavadoc">