This is an automated email from the ASF dual-hosted git repository.

leerho pushed a commit to branch integrateJava17_v3
in repository https://gitbox.apache.org/repos/asf/datasketches-memory.git


The following commit(s) were added to refs/heads/integrateJava17_v3 by this 
push:
     new 88d94c8  Change tests to accommodate:
88d94c8 is described below

commit 88d94c8484828f4abff1779c7bd5c4de0d33e5a3
Author: Lee Rhodes <[email protected]>
AuthorDate: Thu May 30 16:24:21 2024 -0700

    Change tests to accommodate:
    
    - changed WritableMemory::allocateDirect(long, long,ByteOrder,MemReqSvr)
    
    - changed WritableMemory::writableMap(File, long, long, ByteOrder)
    
    - added WritableMemory::writableMap(File, long, long, ResourceScope,
    ByteOrder)
    
    - changed Memory::map(File, long, long, ByteOrder)
    
    - added Memory::map(File, long, long, ResourceScope, ByteOrder)
---
 .../org/apache/datasketches/memory/BaseState.java  | 26 ++++++--
 .../org/apache/datasketches/memory/Memory.java     | 31 ++++++++--
 .../apache/datasketches/memory/WritableMemory.java | 70 ++++++++++++++++------
 .../memory/internal/BaseStateImpl.java             | 19 +++++-
 .../internal/AllocateDirectMapMemoryTest.java      | 21 +++----
 .../memory/internal/AllocateDirectMemoryTest.java  | 14 ++---
 .../AllocateDirectWritableMapMemoryTest.java       | 13 ++--
 .../memory/internal/BaseBufferTest.java            |  3 +-
 .../datasketches/memory/internal/Buffer2Test.java  |  2 +-
 .../memory/internal/BufferInvariantsTest.java      |  5 +-
 .../datasketches/memory/internal/BufferTest.java   |  6 +-
 .../memory/internal/CommonBufferTest.java          | 12 ++--
 .../memory/internal/CommonMemoryTest.java          | 14 +++--
 .../memory/internal/CopyMemoryOverlapTest.java     |  6 +-
 .../memory/internal/CopyMemoryTest.java            |  3 +-
 .../memory/internal/MemoryReadWriteSafetyTest.java |  4 +-
 .../datasketches/memory/internal/MemoryTest.java   | 10 ++--
 .../memory/internal/MemoryWriteToTest.java         |  3 +-
 .../memory/internal/MurmurHash3v3Test.java         |  4 +-
 .../internal/NativeWritableBufferImplTest.java     | 16 ++---
 .../internal/NativeWritableMemoryImplTest.java     | 38 ++++++------
 .../memory/internal/SpecificLeafTest.java          |  2 +-
 .../memory/internal/WritableDirectCopyTest.java    | 26 ++++----
 .../memory/internal/ZeroCapacityTest.java          |  3 +-
 24 files changed, 220 insertions(+), 131 deletions(-)

diff --git a/src/main/java/org/apache/datasketches/memory/BaseState.java 
b/src/main/java/org/apache/datasketches/memory/BaseState.java
index 0eca005..977b98b 100644
--- a/src/main/java/org/apache/datasketches/memory/BaseState.java
+++ b/src/main/java/org/apache/datasketches/memory/BaseState.java
@@ -64,8 +64,8 @@ public interface BaseState {
   ByteBuffer asByteBufferView(ByteOrder order);
 
   /**
-   * For off-heap segments, this closes the controlling ResourceScope. If the 
segment is
-   * not off-heap, this does nothing.
+   * For off-heap segments, this closes the underlying ResourceScope. If the 
segment is
+   * on-heap, this does nothing.
    */
   void close();
 
@@ -104,6 +104,13 @@ public interface BaseState {
    */
   long getCapacity();
 
+  /**
+   * Gets the base offset of <i>that</i> with respect to the base of 
<i>this</i>.
+   * @param that
+   * @return
+   */
+  long getCumulativeOffset(BaseState that);
+  
   /**
    * Returns the configured MemoryRequestSever or null, if it has not been 
configured.
    * @return the configured MemoryRequestSever or null, if it has not been 
configured.
@@ -117,6 +124,12 @@ public interface BaseState {
    */
   ByteOrder getByteOrder();
 
+  /**
+   * Return the owner thread of the underlying ResourceScope, or null.
+   * @return the owner thread of the underlying ResourceScope, or null.
+   */
+  Thread getOwnerThread();
+
   /**
    * Returns true if this Memory is backed by a ByteBuffer.
    * @return true if this Memory is backed by a ByteBuffer.
@@ -202,7 +215,12 @@ public interface BaseState {
    * @return true if this instance is a region view of another Memory or Buffer
    */
   boolean isRegion();
-
+  
+  /**
+   * Returns true if the underlying resource is the same underlying resource 
as <i>that</i>.
+   */
+  boolean isSameResource(BaseState that);
+  
   /**
    * Loads the contents of this mapped segment into physical memory. Please 
refer to
    * <a 
href="https://docs.oracle.com/en/java/javase/17/docs/api/jdk.incubator.foreign/jdk/incubator/foreign/MemorySegment.html#load()">load()</a>
@@ -227,7 +245,7 @@ public interface BaseState {
    * otherwise -1 if no mismatch
    */
   long mismatch(BaseState that);
-
+  
   /**
    * Returns the resource scope associated with this memory segment.
    * @return the resource scope associated with this memory segment.
diff --git a/src/main/java/org/apache/datasketches/memory/Memory.java 
b/src/main/java/org/apache/datasketches/memory/Memory.java
index a4eeb2e..b83238f 100644
--- a/src/main/java/org/apache/datasketches/memory/Memory.java
+++ b/src/main/java/org/apache/datasketches/memory/Memory.java
@@ -71,10 +71,9 @@ public interface Memory extends BaseState {
   /**
    * Maps the given file into <i>Memory</i> for read operations
    * Calling this method is equivalent to calling
-   * {@link #map(File, long, long, ResourceScope, ByteOrder)
+   * {@link #map(File, long, long, ByteOrder)
    * map(file, 0, file.length(), scope, ByteOrder.nativeOrder())}.
    * @param file the given file to map. It must be non-null with a 
non-negative length and readable.
-   * @param scope the given ResourceScope. It must be non-null.
    * @return mapped Memory.
    * @throws IllegalArgumentException -- if file is not readable.
    * @throws IllegalStateException - if scope has been already closed, or if 
access occurs from a thread other
@@ -83,9 +82,9 @@ public interface Memory extends BaseState {
    * @throws SecurityException - If a security manager is installed and it 
denies an unspecified permission
    * required by the implementation.
    */
-  static Memory map(File file, ResourceScope scope)
+  static Memory map(File file)
       throws IllegalArgumentException, IllegalStateException, IOException, 
SecurityException {
-    return map(file, 0, file.length(), scope, ByteOrder.nativeOrder());
+    return map(file, 0, file.length(), ByteOrder.nativeOrder());
   }
 
   /**
@@ -93,7 +92,6 @@ public interface Memory extends BaseState {
    * @param file the given file to map. It must be non-null,readable and 
length &ge; 0.
    * @param fileOffsetBytes the position in the given file in bytes. It must 
not be negative.
    * @param capacityBytes the size of the mapped memory. It must not be 
negative..
-   * @param scope the given ResourceScope. It must be non-null.
    * @param byteOrder the byte order to be used.  It must be non-null.
    * @return mapped Memory
    * @throws IllegalArgumentException -- if file is not readable.
@@ -103,11 +101,32 @@ public interface Memory extends BaseState {
    * @throws SecurityException - If a security manager is installed and it 
denies an unspecified permission
    * required by the implementation.
    */
-  static Memory map(File file, long fileOffsetBytes, long capacityBytes, 
ResourceScope scope, ByteOrder byteOrder)
+  static Memory map(File file, long fileOffsetBytes, long capacityBytes, 
ByteOrder byteOrder)
       throws IllegalArgumentException, IllegalStateException, IOException, 
SecurityException {
+         final ResourceScope scope = ResourceScope.newConfinedScope();
     return BaseWritableMemoryImpl.wrapMap(file, fileOffsetBytes, 
capacityBytes, scope, true, byteOrder);
   }
 
+  /**
+   * Maps the specified portion of the given file into <i>Memory</i> for read 
operations with a ResourceScope.
+   * @param file the given file to map. It must be non-null,readable and 
length &ge; 0.
+   * @param fileOffsetBytes the position in the given file in bytes. It must 
not be negative.
+   * @param capacityBytes the size of the mapped memory. It must not be 
negative.
+   * @param scope the given ResourceScope.
+   * @param byteOrder the byte order to be used.  It must be non-null.
+   * @return mapped Memory
+   * @throws IllegalArgumentException -- if file is not readable.
+   * @throws IllegalStateException - if scope has been already closed, or if 
access occurs from a thread other
+   * than the thread owning scope.
+   * @throws IOException - if the specified path does not point to an existing 
file, or if some other I/O error occurs.
+   * @throws SecurityException - If a security manager is installed and it 
denies an unspecified permission
+   * required by the implementation.
+   */
+  static Memory map(File file, long fileOffsetBytes, long capacityBytes, 
ResourceScope scope, ByteOrder byteOrder)
+      throws IllegalArgumentException, IllegalStateException, IOException, 
SecurityException {
+    return BaseWritableMemoryImpl.wrapMap(file, fileOffsetBytes, 
capacityBytes, scope, true, byteOrder);
+  }
+  
   //NO ALLOCATE DIRECT, makes no sense
 
   //REGIONS
diff --git a/src/main/java/org/apache/datasketches/memory/WritableMemory.java 
b/src/main/java/org/apache/datasketches/memory/WritableMemory.java
index 321090f..1ad46ed 100644
--- a/src/main/java/org/apache/datasketches/memory/WritableMemory.java
+++ b/src/main/java/org/apache/datasketches/memory/WritableMemory.java
@@ -72,22 +72,19 @@ public interface WritableMemory extends Memory {
   /**
    * Maps the entire given file into native-ordered WritableMemory for write 
operations
    * Calling this method is equivalent to calling
-   * {@link #writableMap(File, long, long, ResourceScope, ByteOrder)
+   * {@link #writableMap(File, long, long, ByteOrder)
    *   writableMap(file, 0, file.length(), scope, ByteOrder.nativeOrder())}.
    * @param file the given file to map. It must be non-null with a 
non-negative length and writable.
-   * @param scope the give Resource Scope. It must be non-null.
    * @return mapped WritableMemory
    * @throws IllegalArgumentException -- if file is not readable.
    * @throws IllegalArgumentException -- if file is not writable.
-   * @throws IllegalStateException - if scope has been already closed, or if 
access occurs from a thread other
-   * than the thread owning scope.
    * @throws IOException - if the specified path does not point to an existing 
file, or if some other I/O error occurs.
    * @throws SecurityException - If a security manager is installed and it 
denies an unspecified permission
    * required by the implementation.
    */
-  static WritableMemory writableMap(File file, ResourceScope scope)
+  static WritableMemory writableMap(File file)
       throws IllegalArgumentException, IllegalStateException, IOException, 
SecurityException {
-    return writableMap(file, 0, file.length(), scope, ByteOrder.nativeOrder());
+    return writableMap(file, 0, file.length(), ByteOrder.nativeOrder());
   }
 
   /**
@@ -95,22 +92,39 @@ public interface WritableMemory extends Memory {
    * @param file the given file to map. It must be non-null with a 
non-negative length and writable.
    * @param fileOffsetBytes the position in the given file in bytes. It must 
not be negative.
    * @param capacityBytes the size of the mapped Memory. It must be &ge; 0.
-   * @param scope the give Resource Scope. It must be non-null.
    * @param byteOrder the byte order to be used.  It must be non-null.
    * @return mapped WritableMemory.
    * @throws IllegalArgumentException -- if file is not readable or writable.
    * @throws IllegalArgumentException -- if file is not writable.
-   * @throws IllegalStateException - if scope has been already closed, or if 
access occurs from a thread other
-   * than the thread owning scope.
    * @throws IOException - if the specified path does not point to an existing 
file, or if some other I/O error occurs.
    * @throws SecurityException - If a security manager is installed and it 
denies an unspecified permission
    * required by the implementation.
    */
-  static WritableMemory writableMap(File file, long fileOffsetBytes, long 
capacityBytes, ResourceScope scope,
-      ByteOrder byteOrder) throws IllegalArgumentException, 
IllegalStateException, IOException, SecurityException {
+  static WritableMemory writableMap(File file, long fileOffsetBytes, long 
capacityBytes, ByteOrder byteOrder) 
+                 throws IllegalArgumentException, IllegalStateException, 
IOException, SecurityException {
+         ResourceScope scope = ResourceScope.newConfinedScope();
     return BaseWritableMemoryImpl.wrapMap(file, fileOffsetBytes, 
capacityBytes, scope, false, byteOrder);
   }
 
+  /**
+   * Maps the specified portion of the given file into Memory for write 
operations with a ResourceScope.
+   * @param file the given file to map. It must be non-null with a 
non-negative length and writable.
+   * @param fileOffsetBytes the position in the given file in bytes. It must 
not be negative.
+   * @param capacityBytes the size of the mapped Memory. It must be &ge; 0.
+   * @param scope the given ResourceScope.
+   * @param byteOrder the byte order to be used.  It must be non-null.
+   * @return mapped WritableMemory.
+   * @throws IllegalArgumentException -- if file is not readable or writable.
+   * @throws IllegalArgumentException -- if file is not writable.
+   * @throws IOException - if the specified path does not point to an existing 
file, or if some other I/O error occurs.
+   * @throws SecurityException - If a security manager is installed and it 
denies an unspecified permission
+   * required by the implementation.
+   */
+  static WritableMemory writableMap(File file, long fileOffsetBytes, long 
capacityBytes, ResourceScope scope, ByteOrder byteOrder) 
+                 throws IllegalArgumentException, IllegalStateException, 
IOException, SecurityException {
+    return BaseWritableMemoryImpl.wrapMap(file, fileOffsetBytes, 
capacityBytes, scope, false, byteOrder);
+  }
+  
   //ALLOCATE DIRECT
 
   /**
@@ -121,12 +135,11 @@ public interface WritableMemory extends Memory {
    * <p><b>NOTICE:</b> It is the responsibility of the using application to 
call <i>close()</i> when done.</p>
    *
    * @param capacityBytes the size of the desired memory in bytes.
-   * @param scope the given ResourceScope. It must be non-null.
    * @param memReqSvr A user-specified MemoryRequestServer, which may be null.
    * @return WritableMemory for this off-heap, native resource.
    */
-  static WritableMemory allocateDirect(long capacityBytes, ResourceScope 
scope, MemoryRequestServer memReqSvr) {
-    return allocateDirect(capacityBytes, 8, scope, ByteOrder.nativeOrder(), 
memReqSvr);
+  static WritableMemory allocateDirect(long capacityBytes, MemoryRequestServer 
memReqSvr) {
+    return allocateDirect(capacityBytes, 8, ByteOrder.nativeOrder(), 
memReqSvr);
   }
 
   /**
@@ -138,7 +151,6 @@ public interface WritableMemory extends Memory {
    *
    * @param capacityBytes the size of the desired memory in bytes.
    * @param alignmentBytes requested segment alignment. Typically 1, 2, 4 or 8.
-   * @param scope the given ResourceScope. It must be non-null.
    * @param byteOrder the byte order to be used.  It must be non-null.
    * @param memReqSvr A user-specified MemoryRequestServer, which may be null.
    * This is a callback mechanism for a user client of direct memory to 
request more memory.
@@ -147,12 +159,36 @@ public interface WritableMemory extends Memory {
   static WritableMemory allocateDirect(
       long capacityBytes,
       long alignmentBytes,
-      ResourceScope scope,
       ByteOrder byteOrder,
       MemoryRequestServer memReqSvr) {
+         final ResourceScope scope = ResourceScope.newConfinedScope();
     return BaseWritableMemoryImpl.wrapDirect(capacityBytes, alignmentBytes, 
scope, byteOrder, memReqSvr);
   }
 
+  /**
+   * Allocates and provides access to capacityBytes directly in native 
(off-heap) memory with a ResourceScope.
+   * The allocated memory will be aligned to the given <i>alignmentBytes</i>.
+   *
+   * <p><b>NOTICE:</b> It is the responsibility of the using application to
+   * call <i>close()</i> when done.</p>
+   *
+   * @param capacityBytes the size of the desired memory in bytes.
+   * @param alignmentBytes requested segment alignment. Typically 1, 2, 4 or 8.
+   * @param scope the given ResourceScope.
+   * @param byteOrder the byte order to be used.  It must be non-null.
+   * @param memReqSvr A user-specified MemoryRequestServer, which may be null.
+   * This is a callback mechanism for a user client of direct memory to 
request more memory.
+   * @return WritableMemory
+   */
+  static WritableMemory allocateDirect(
+      long capacityBytes,
+      long alignmentBytes,
+      ResourceScope scope,
+      ByteOrder byteOrder,
+      MemoryRequestServer memReqSvr) {
+    return BaseWritableMemoryImpl.wrapDirect(capacityBytes, alignmentBytes, 
scope, byteOrder, memReqSvr);
+  }
+  
   //REGIONS
   /**
    * A writable region is a writable view of this object.
@@ -554,7 +590,7 @@ public interface WritableMemory extends Memory {
    * Gets the MemoryRequestServer implementation, if set, to request 
additional memory.
    * The user must customize the actions of the MemoryRequestServer by
    * implementing the MemoryRequestServer interface and set using this method:
-   * {@link WritableMemory#allocateDirect(long, long, ResourceScope, 
ByteOrder, MemoryRequestServer)}.
+   * {@link WritableMemory#allocateDirect(long, long, ByteOrder, 
MemoryRequestServer)}.
    * Simple implementation examples include the DefaultMemoryRequestServer in 
the main tree, as well as
    * the ExampleMemoryRequestServerTest and the use with ByteBuffer documented 
in the DruidIssue11544Test
    * in the test tree.
diff --git 
a/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java 
b/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
index 575f3c7..012791c 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
@@ -302,6 +302,12 @@ abstract class BaseStateImpl implements BaseState {
     return seg.byteSize();
   }
 
+  @Override
+  public final long getCumulativeOffset(final BaseState that) {
+         final BaseStateImpl that2 = (BaseStateImpl) that;
+         return this.seg.address().segmentOffset(that2.seg);
+  }
+  
   @Override
   public MemoryRequestServer getMemoryRequestServer() {
     return memReqSvr;
@@ -312,6 +318,11 @@ abstract class BaseStateImpl implements BaseState {
     return (typeId & NONNATIVE) > 0 ? NON_NATIVE_BYTE_ORDER : 
ByteOrder.nativeOrder();
   }
 
+  @Override
+  public Thread getOwnerThread() {
+         return seg.scope().ownerThread();
+  }
+  
   @Override
   public final boolean hasByteBuffer() {
     return (typeId & BYTEBUF) > 0;
@@ -377,7 +388,13 @@ abstract class BaseStateImpl implements BaseState {
   public final boolean isRegion() {
     return (typeId & REGION) > 0;
   }
-
+  
+  @Override
+  public final boolean isSameResource(BaseState that) {
+         BaseStateImpl that2 = (BaseStateImpl) that;
+         return this.seg.address().equals(that2.seg.address());
+  }
+  
   @Override
   public void load() { seg.load(); }
 
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
 
b/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
index 161eb1b..64162be 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
@@ -45,8 +45,7 @@ public class AllocateDirectMapMemoryTest {
     File file = getResourceFile("GettysburgAddress.txt");
     file.setReadOnly();
     Memory mem = null;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      mem = Memory.map(file, scope);
+    try (ResourceScope scope = (mem = Memory.map(file)).scope()) {
     }
     assertFalse(mem.isAlive());
   }
@@ -55,16 +54,14 @@ public class AllocateDirectMapMemoryTest {
   public void testIllegalArguments() throws Exception {
     File file = getResourceFile("GettysburgAddress.txt");
     Memory mem = null;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      mem = Memory.map(file, -1, Integer.MAX_VALUE, scope, 
ByteOrder.nativeOrder());
+    try (ResourceScope scope = (mem = Memory.map(file, -1, Integer.MAX_VALUE, 
ByteOrder.nativeOrder())).scope();) {
       fail("Failed: test IllegalArgumentException: Position was negative.");
       mem.getCapacity();
     }
     catch (IllegalArgumentException e) {
       //ok
     }
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      mem = Memory.map(file, 0, -1, scope, ByteOrder.nativeOrder());
+    try (ResourceScope scope = (mem = Memory.map(file, 0, -1, 
ByteOrder.nativeOrder())).scope()) {
       fail("Failed: testIllegalArgumentException: Size was negative.");
     } catch (IllegalArgumentException e) {
       //ok
@@ -76,10 +73,9 @@ public class AllocateDirectMapMemoryTest {
     File file = getResourceFile("GettysburgAddress.txt");
     long memCapacity = file.length();
     Memory mem = null;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      mem = Memory.map(file, 0, memCapacity, scope, ByteOrder.nativeOrder());
+    try (ResourceScope scope = (mem = Memory.map(file, 0, memCapacity, 
ByteOrder.nativeOrder())).scope()) {
       assertEquals(memCapacity, mem.getCapacity());
-      //mem.close(); //a close inside the TWR block will throw excption when 
the TWR block ends
+      //mem.close(); //a close inside the TWR block will throw exception when 
the TWR block ends
     }
     mem.close(); //multiple closes outside the TWR block are OK, but 
unnecessary
     mem.close();
@@ -90,8 +86,7 @@ public class AllocateDirectMapMemoryTest {
     File file = getResourceFile("GettysburgAddress.txt");
     long memCapacity = file.length();
     Memory mem = null;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      mem = Memory.map(file, 0, memCapacity, scope, ByteOrder.nativeOrder());
+    try (ResourceScope scope = (mem = Memory.map(file, 0, memCapacity, 
ByteOrder.nativeOrder())).scope()) {
       mem.load();
       assertTrue(mem.isLoaded());
     }
@@ -102,8 +97,8 @@ public class AllocateDirectMapMemoryTest {
   public void testHandleHandoff() throws Exception {
     File file = getResourceFile("GettysburgAddress.txt");
     long memCapacity = file.length();
-    ResourceScope scope = ResourceScope.newConfinedScope();
-    Memory mem = Memory.map(file, 0, memCapacity, scope, 
ByteOrder.nativeOrder());
+    Memory mem = Memory.map(file, 0, memCapacity, ByteOrder.nativeOrder());
+    ResourceScope scope = mem.scope();
     ResourceScope.Handle handle = scope.acquire();
     try {
       mem.load();
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMemoryTest.java
 
b/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMemoryTest.java
index 0497a66..4a2b684 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMemoryTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMemoryTest.java
@@ -38,8 +38,7 @@ public class AllocateDirectMemoryTest {
   public void simpleAllocateDirect() {
     int longs = 32;
     WritableMemory wMem = null;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      wMem = WritableMemory.allocateDirect(longs << 3, scope, memReqSvr);
+    try (ResourceScope scope = (wMem = WritableMemory.allocateDirect(longs << 
3, memReqSvr)).scope()) {
       for (int i = 0; i<longs; i++) {
         wMem.putLong(i << 3, i);
         assertEquals(wMem.getLong(i << 3), i);
@@ -56,9 +55,7 @@ public class AllocateDirectMemoryTest {
     int longs1 = 32;
     int bytes1 = longs1 << 3;
     WritableMemory wmem = null;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      wmem = WritableMemory.allocateDirect(bytes1, scope, memReqSvr);
-
+    try (ResourceScope scope = (wmem = WritableMemory.allocateDirect(bytes1, 
memReqSvr)).scope()) {
       for (int i = 0; i < longs1; i++) { //puts data in origWmem
         wmem.putLong(i << 3, i);
         assertEquals(wmem.getLong(i << 3), i);
@@ -81,9 +78,7 @@ public class AllocateDirectMemoryTest {
   @Test
   public void checkNonNativeDirect() {
     WritableMemory wmem = null;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      wmem = WritableMemory.allocateDirect( 128, 8, scope,
-          BaseState.NON_NATIVE_BYTE_ORDER, memReqSvr);
+    try (ResourceScope scope = (wmem = WritableMemory.allocateDirect(128, 8, 
BaseState.NON_NATIVE_BYTE_ORDER, memReqSvr)).scope()) {
       wmem.putChar(0, (char) 1);
       assertEquals(wmem.getByte(1), (byte) 1);
     }
@@ -94,8 +89,7 @@ public class AllocateDirectMemoryTest {
   public void checkExplicitCloseNoTWR() {
     final long cap = 128;
     WritableMemory wmem = null;
-    ResourceScope scope = ResourceScope.newConfinedScope();
-    wmem = WritableMemory.allocateDirect(cap, scope, memReqSvr);
+    wmem = WritableMemory.allocateDirect(cap, memReqSvr);
     wmem.close(); //explicit close
   }
 
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
 
b/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
index 76aa2a0..14dee0b 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
@@ -61,8 +61,7 @@ public class AllocateDirectWritableMapMemoryTest {
       UnsupportedOperationException, IOException, SecurityException {
     File file = getResourceFile("GettysburgAddress.txt");
     Memory mem = null;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      mem = Memory.map(file,scope);
+    try (ResourceScope scope = (mem = Memory.map(file)).scope()) {
       byte[] byteArr = new byte[(int)mem.getCapacity()];
       mem.getByteArray(0, byteArr, 0, byteArr.length);
       String text = new String(byteArr, UTF_8);
@@ -88,11 +87,10 @@ public class AllocateDirectWritableMapMemoryTest {
     file.deleteOnExit();  //comment out if you want to examine the file.
 
     WritableMemory dstMem = null;
+    WritableMemory srcMem = null;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) { //this 
scope manages two Memory objects
-      dstMem = WritableMemory.writableMap(file, 0, numBytes, scope, 
ByteOrder.nativeOrder());
-
-      WritableMemory srcMem
-        = WritableMemory.allocateDirect(numBytes, 8, scope, 
ByteOrder.nativeOrder(), memReqSvr);
+      dstMem = WritableMemory.writableMap(file, 0, numBytes, scope, 
ByteOrder.nativeOrder());  
+      srcMem = WritableMemory.allocateDirect(numBytes, 8, scope, 
ByteOrder.nativeOrder(), memReqSvr);
 
       //load source with consecutive longs
       for (long i = 0; i < numLongs; i++) {
@@ -147,8 +145,7 @@ public class AllocateDirectWritableMapMemoryTest {
     assertTrue(file.canRead());
     assertFalse(file.canWrite());
     WritableMemory wmem = null;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      wmem = WritableMemory.writableMap(file, scope); //throws 
ReadOnlyException
+    try (ResourceScope scope = (wmem = 
WritableMemory.writableMap(file)).scope()) { //throws ReadOnlyException
       wmem.getCapacity();
     }
   }
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/BaseBufferTest.java 
b/src/test/java/org/apache/datasketches/memory/internal/BaseBufferTest.java
index 73cd01f..14ba7c7 100644
--- a/src/test/java/org/apache/datasketches/memory/internal/BaseBufferTest.java
+++ b/src/test/java/org/apache/datasketches/memory/internal/BaseBufferTest.java
@@ -81,8 +81,7 @@ public class BaseBufferTest {
   public void checkCheckNotAliveAfterTWR() {
     WritableMemory wmem;
     Buffer buf;
-    try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      wmem = WritableMemory.allocateDirect(100, scope, memReqSvr);
+    try (ResourceScope scope = (wmem = WritableMemory.allocateDirect(100, 
memReqSvr)).scope()) {
       buf = wmem.asBuffer();
     }
     try {
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java 
b/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java
index d1eb6cb..a5849da 100644
--- a/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java
+++ b/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java
@@ -401,7 +401,7 @@ public class Buffer2Test {
   public void checkIndependence() {
     int cap = 64;
     ResourceScope scope = ResourceScope.newImplicitScope();
-    WritableMemory wmem = WritableMemory.allocateDirect(cap, scope, null);
+    WritableMemory wmem = WritableMemory.allocateDirect(cap, 8, scope, 
ByteOrder.nativeOrder(), null);
     WritableBuffer wbuf1 = wmem.asWritableBuffer();
     WritableBuffer wbuf2 = wmem.asWritableBuffer();
     assertFalse(wbuf1 == wbuf2);
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/BufferInvariantsTest.java
 
b/src/test/java/org/apache/datasketches/memory/internal/BufferInvariantsTest.java
index 4b233be..091bf35 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/BufferInvariantsTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/BufferInvariantsTest.java
@@ -23,6 +23,7 @@ import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.fail;
 
 import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
 
 import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.Buffer;
@@ -166,7 +167,7 @@ public class BufferInvariantsTest {
   @Test
   public void checkLimitsDirect() throws Exception {
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory wmem = WritableMemory.allocateDirect(100, scope, 
memReqSvr);
+      WritableMemory wmem = WritableMemory.allocateDirect(100, 1, scope, 
ByteOrder.nativeOrder(), memReqSvr);
       Buffer buf = wmem.asBuffer();
       buf.setStartPositionEnd(40, 45, 50);
       buf.setStartPositionEnd(0, 0, 100);
@@ -237,7 +238,7 @@ public class BufferInvariantsTest {
   public void testBufDirect() throws Exception {
     int n = 25;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-    WritableMemory wmem = WritableMemory.allocateDirect(n, scope, memReqSvr);
+    WritableMemory wmem = WritableMemory.allocateDirect(n, 1, scope, 
ByteOrder.nativeOrder(), memReqSvr);
     WritableBuffer buf = wmem.asWritableBuffer();
     for (byte i = 0; i < n; i++) { buf.putByte(i); }
     buf.setPosition(0);
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/BufferTest.java 
b/src/test/java/org/apache/datasketches/memory/internal/BufferTest.java
index c9e58f0..25f2baf 100644
--- a/src/test/java/org/apache/datasketches/memory/internal/BufferTest.java
+++ b/src/test/java/org/apache/datasketches/memory/internal/BufferTest.java
@@ -42,7 +42,7 @@ public class BufferTest {
   public void checkDirectRoundTrip() throws Exception {
     int n = 1024; //longs
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-    WritableMemory wmem = WritableMemory.allocateDirect(n * 8, scope, 
memReqSvr);
+    WritableMemory wmem = WritableMemory.allocateDirect(n * 8, 1, scope, 
ByteOrder.nativeOrder(), memReqSvr);
       WritableBuffer wbuf = wmem.asWritableBuffer();
       for (int i = 0; i < n; i++) {
         wbuf.putLong(i);
@@ -285,7 +285,7 @@ public class BufferTest {
   @Test(expectedExceptions = IllegalStateException.class)
   public void checkParentUseAfterFree() throws Exception {
     int bytes = 64 * 8;
-    WritableMemory wmem = WritableMemory.allocateDirect(bytes, 
ResourceScope.newConfinedScope(), memReqSvr);
+    WritableMemory wmem = WritableMemory.allocateDirect(bytes, 1, 
ResourceScope.newConfinedScope(), ByteOrder.nativeOrder(), memReqSvr);
     WritableBuffer wbuf = wmem.asWritableBuffer();
     wbuf.close();
     //with -ea assert: Memory not valid.
@@ -297,7 +297,7 @@ public class BufferTest {
   @Test(expectedExceptions = IllegalStateException.class)
   public void checkRegionUseAfterFree() throws Exception {
     int bytes = 64;
-    WritableMemory wmem = WritableMemory.allocateDirect(bytes, 
ResourceScope.newConfinedScope(), memReqSvr);
+    WritableMemory wmem = WritableMemory.allocateDirect(bytes, 1, 
ResourceScope.newConfinedScope(), ByteOrder.nativeOrder(), memReqSvr);
     Buffer region = wmem.asBuffer().region();
     region.close();
     //with -ea assert: Memory not valid.
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/CommonBufferTest.java 
b/src/test/java/org/apache/datasketches/memory/internal/CommonBufferTest.java
index 8d3b519..ecfa2a9 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/CommonBufferTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/CommonBufferTest.java
@@ -21,6 +21,8 @@ package org.apache.datasketches.memory.internal;
 
 import static org.testng.Assert.assertEquals;
 
+import java.nio.ByteOrder;
+
 import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.MemoryRequestServer;
 import org.apache.datasketches.memory.WritableBuffer;
@@ -35,7 +37,7 @@ public class CommonBufferTest {
   public void checkSetGet() throws Exception {
     int memCapacity = 60; //must be at least 60
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, 1, 
scope,ByteOrder.nativeOrder(), memReqSvr);
       WritableBuffer buf = mem.asWritableBuffer();
       assertEquals(buf.getCapacity(), memCapacity);
       setGetTests(buf);
@@ -137,7 +139,7 @@ public class CommonBufferTest {
   public void checkSetGetArrays() throws Exception {
     int memCapacity = 32;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       WritableBuffer buf = mem.asWritableBuffer();
       assertEquals(buf.getCapacity(), memCapacity);
       setGetArraysTests(buf);
@@ -222,7 +224,7 @@ public class CommonBufferTest {
   public void checkSetGetPartialArraysWithOffset() throws Exception {
     int memCapacity = 32;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       WritableBuffer buf = mem.asWritableBuffer();
       assertEquals(buf.getCapacity(), memCapacity);
       setGetPartialArraysWithOffsetTests(buf);
@@ -307,7 +309,7 @@ public class CommonBufferTest {
   public void checkSetClearMemoryRegions() throws Exception {
     int memCapacity = 64; //must be 64
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       WritableBuffer buf = mem.asWritableBuffer();
       assertEquals(buf.getCapacity(), memCapacity);
 
@@ -396,7 +398,7 @@ public class CommonBufferTest {
   public void checkToHexStringAllMem() throws Exception {
     int memCapacity = 48; //must be 48
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       WritableBuffer buf = mem.asWritableBuffer();
       assertEquals(buf.getCapacity(), memCapacity);
       toHexStringAllMemTests(buf); //requires println enabled to visually check
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/CommonMemoryTest.java 
b/src/test/java/org/apache/datasketches/memory/internal/CommonMemoryTest.java
index 9245a59..d48d486 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/CommonMemoryTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/CommonMemoryTest.java
@@ -27,6 +27,8 @@ import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
 
+import java.nio.ByteOrder;
+
 import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.MemoryRequestServer;
 import org.apache.datasketches.memory.WritableMemory;
@@ -40,7 +42,7 @@ public class CommonMemoryTest {
   public void checkSetGet() throws Exception {
     int memCapacity = 16; //must be at least 8
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       assertEquals(mem.getCapacity(), memCapacity);
       setGetTests(mem);
     }
@@ -92,7 +94,7 @@ public class CommonMemoryTest {
   public void checkSetGetArrays() throws Exception {
     int memCapacity = 32;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       assertEquals(memCapacity, mem.getCapacity());
       setGetArraysTests(mem);
     }
@@ -162,7 +164,7 @@ public class CommonMemoryTest {
   public void checkSetGetPartialArraysWithOffset() throws Exception {
     int memCapacity = 32;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       assertEquals(memCapacity, mem.getCapacity());
       setGetPartialArraysWithOffsetTests(mem);
     }
@@ -232,7 +234,7 @@ public class CommonMemoryTest {
   public void checkSetClearIsBits() throws Exception {
     int memCapacity = 8;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       assertEquals(memCapacity, mem.getCapacity());
       mem.clear();
       setClearIsBitsTests(mem);
@@ -273,7 +275,7 @@ public class CommonMemoryTest {
   public void checkSetClearMemoryRegions() throws Exception {
     int memCapacity = 64; //must be 64
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
 
       setClearMemoryRegionsTests(mem); //requires println enabled to visually 
check
       for (int i = 0; i < memCapacity; i++) {
@@ -344,7 +346,7 @@ public class CommonMemoryTest {
   public void checkToHexStringAllMem() throws Exception {
     int memCapacity = 48; //must be 48
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       toHexStringAllMemTests(mem); //requires println enabled to visually check
     }
   }
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryOverlapTest.java
 
b/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryOverlapTest.java
index 8a4bdc0..13813ad 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryOverlapTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryOverlapTest.java
@@ -21,6 +21,8 @@ package org.apache.datasketches.memory.internal;
 
 import static org.testng.Assert.assertEquals;
 
+import java.nio.ByteOrder;
+
 import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.MemoryRequestServer;
@@ -97,7 +99,7 @@ public class CopyMemoryOverlapTest {
     println("Backing longs: " + backingLongs + "\t bytes: " + backingBytes);
 
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory backingMem = WritableMemory.allocateDirect(backingBytes, 
scope, memReqSvr);
+      WritableMemory backingMem = WritableMemory.allocateDirect(backingBytes,  
1, scope, ByteOrder.nativeOrder(), memReqSvr);
       fill(backingMem); //fill mem with 0 thru copyLongs -1
       //listMem(backingMem, "Original");
       backingMem.copyTo(fromOffsetBytes, backingMem, toOffsetBytes, copyBytes);
@@ -137,7 +139,7 @@ public class CopyMemoryOverlapTest {
     println("Backing longs: " + backingLongs + "\t bytes: " + backingBytes);
 
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory backingMem = WritableMemory.allocateDirect(backingBytes, 
scope, memReqSvr);
+      WritableMemory backingMem = WritableMemory.allocateDirect(backingBytes, 
1, scope, ByteOrder.nativeOrder(), memReqSvr);
       fill(backingMem); //fill mem with 0 thru copyLongs -1
       //listMem(backingMem, "Original");
       WritableMemory reg1 = backingMem.writableRegion(fromOffsetBytes, 
copyBytes);
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryTest.java 
b/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryTest.java
index f0af8c4..7ef0a84 100644
--- a/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryTest.java
+++ b/src/test/java/org/apache/datasketches/memory/internal/CopyMemoryTest.java
@@ -21,6 +21,7 @@ package org.apache.datasketches.memory.internal;
 
 import static org.testng.Assert.assertEquals;
 
+import java.nio.ByteOrder;
 import java.util.concurrent.ThreadLocalRandom;
 
 import org.apache.datasketches.memory.BaseState;
@@ -151,7 +152,7 @@ public class CopyMemoryTest {
 
   @SuppressWarnings("resource")
   private static WritableMemory genWmem(int longs, boolean empty) {
-    WritableMemory wmem = WritableMemory.allocateDirect(longs << 3, 
ResourceScope.newConfinedScope(), memReqSvr);
+    WritableMemory wmem = WritableMemory.allocateDirect(longs << 3, 1, 
ResourceScope.newConfinedScope(), ByteOrder.nativeOrder(), memReqSvr);
     if (empty) {
       wmem.clear();
     } else {
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/MemoryReadWriteSafetyTest.java
 
b/src/test/java/org/apache/datasketches/memory/internal/MemoryReadWriteSafetyTest.java
index 0b3b8fb..c536e1c 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/MemoryReadWriteSafetyTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/MemoryReadWriteSafetyTest.java
@@ -182,9 +182,9 @@ public class MemoryReadWriteSafetyTest {
     tempFile.deleteOnExit();
     try (RandomAccessFile raf = new RandomAccessFile(tempFile, "rw")) {
       raf.setLength(8);
+      Memory mem = null;
       //System.out.println(UtilTest.getFileAttributes(tempFile));
-      try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-        Memory mem = Memory.map(tempFile, scope);
+      try (ResourceScope scope = (mem = Memory.map(tempFile)).scope()) {
         ((WritableMemory) mem).putInt(0, 1);
       }
     }
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java 
b/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
index bc0796c..49752fc 100644
--- a/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
+++ b/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
@@ -59,7 +59,7 @@ public class MemoryTest {
   public void checkDirectRoundTrip() throws Exception {
     int n = 1024; //longs
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem = WritableMemory.allocateDirect(n * 8, scope, 
memReqSvr);
+      WritableMemory mem = WritableMemory.allocateDirect(n * 8, 1, scope, 
ByteOrder.nativeOrder(), memReqSvr);
       for (int i = 0; i < n; i++) {
         mem.putLong(i * 8, i);
       }
@@ -356,7 +356,7 @@ public class MemoryTest {
   public void checkParentUseAfterFree() throws Exception {
     int bytes = 64 * 8;
     ResourceScope scope = ResourceScope.newConfinedScope();
-    WritableMemory wmem = WritableMemory.allocateDirect(bytes, scope, 
memReqSvr);
+    WritableMemory wmem = WritableMemory.allocateDirect(bytes, 1, scope, 
ByteOrder.nativeOrder(), memReqSvr);
     wmem.close();
     //with -ea assert: Memory not valid.
     //with -da sometimes segfaults, sometimes passes!
@@ -368,7 +368,7 @@ public class MemoryTest {
   public void checkRegionUseAfterFree() throws Exception {
     int bytes = 64;
     ResourceScope scope = ResourceScope.newConfinedScope();
-    WritableMemory wmem = WritableMemory.allocateDirect(bytes, scope, 
memReqSvr);
+    WritableMemory wmem = WritableMemory.allocateDirect(bytes, 1, scope, 
ByteOrder.nativeOrder(), memReqSvr);
     Memory region = wmem.region(0L, bytes);
     wmem.close();
     //with -ea assert: Memory not valid.
@@ -388,7 +388,7 @@ public class MemoryTest {
     assertNull(wbuf.getMemoryRequestServer());
     //OFF HEAP
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-       wmem = WritableMemory.allocateDirect(16, scope, memReqSvr);  //OFF HEAP
+       wmem = WritableMemory.allocateDirect(16, 1, scope, 
ByteOrder.nativeOrder(), memReqSvr);  //OFF HEAP
       assertNotNull(wmem.getMemoryRequestServer());
       wbuf = wmem.asWritableBuffer();
       assertNotNull(wbuf.getMemoryRequestServer());
@@ -407,7 +407,7 @@ public class MemoryTest {
     assertNotNull(wbuf.getMemoryRequestServer());
     //OFF HEAP
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory wmem2 = WritableMemory.allocateDirect(16, scope, 
memReqSvr);
+      WritableMemory wmem2 = WritableMemory.allocateDirect(16, 1, scope, 
ByteOrder.nativeOrder(), memReqSvr);
       assertNotNull(wmem2.getMemoryRequestServer());
       wbuf = wmem.asWritableBuffer();
       assertNotNull(wbuf.getMemoryRequestServer());
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/MemoryWriteToTest.java 
b/src/test/java/org/apache/datasketches/memory/internal/MemoryWriteToTest.java
index f995154..2160d1a 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/MemoryWriteToTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/MemoryWriteToTest.java
@@ -24,6 +24,7 @@ import static org.testng.Assert.assertTrue;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.nio.ByteOrder;
 import java.util.concurrent.ThreadLocalRandom;
 
 import org.apache.datasketches.memory.BaseState;
@@ -60,7 +61,7 @@ public class MemoryWriteToTest {
   @Test
   public void testOffHeap() throws Exception {
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem = WritableMemory.allocateDirect(((1 << 20) * 5) + 10, 
scope, memReqSvr);
+      WritableMemory mem = WritableMemory.allocateDirect(((1 << 20) * 5) + 10, 
1, scope, ByteOrder.nativeOrder(), memReqSvr);
       testWriteTo(mem.region(0, 0));
       testOffHeap(mem, 7);
       testOffHeap(mem, 1023);
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/MurmurHash3v3Test.java 
b/src/test/java/org/apache/datasketches/memory/internal/MurmurHash3v3Test.java
index 3d4ce07..59fe167 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/MurmurHash3v3Test.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/MurmurHash3v3Test.java
@@ -23,6 +23,8 @@ import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.apache.datasketches.memory.MurmurHash3.*;
 import static org.testng.Assert.fail;
 
+import java.nio.ByteOrder;
+
 import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.MemoryRequestServer;
@@ -275,7 +277,7 @@ public class MurmurHash3v3Test {
       out = hash(mem, 0L, 4L, 1L, out);
     } catch (final IllegalArgumentException e) { }
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      Memory mem = WritableMemory.allocateDirect(8, scope, memReqSvr);
+      Memory mem = WritableMemory.allocateDirect(8, 1, scope, 
ByteOrder.nativeOrder(), memReqSvr);
       long[] out = new long[2];
       out = hash(mem, 0L, 4L, 1L, out);
     } catch (Exception ee) {}
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java
 
b/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java
index 31957de..c7ea876 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java
@@ -48,7 +48,7 @@ public class NativeWritableBufferImplTest {
   public void checkNativeCapacityAndClose() throws Exception {
     int memCapacity = 64;
     ResourceScope scope = ResourceScope.newConfinedScope();
-    WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+    WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, 1, scope, 
ByteOrder.nativeOrder(), memReqSvr);
     WritableBuffer wbuf = wmem.asWritableBuffer();
     assertEquals(wbuf.getCapacity(), memCapacity);
 
@@ -189,7 +189,7 @@ public class NativeWritableBufferImplTest {
   public void checkNativeBaseBound() throws Exception {
     int memCapacity = 64;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       WritableBuffer wbuf = wmem.asWritableBuffer();
       wbuf.toHexString("Force Assertion Error", memCapacity, 8, false);
     } catch (IllegalArgumentException e) {
@@ -201,7 +201,7 @@ public class NativeWritableBufferImplTest {
   public void checkNativeSrcArrayBound() throws Exception {
     long memCapacity = 64;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       WritableBuffer wbuf = wmem.asWritableBuffer();
       byte[] srcArray = { 1, -2, 3, -4 };
       wbuf.putByteArray(srcArray, 0, 5); //wrong!
@@ -214,7 +214,7 @@ public class NativeWritableBufferImplTest {
   public void checkRegionBounds() throws Exception {
     int memCapacity = 64;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       WritableBuffer wbuf = wmem.asWritableBuffer();
       wbuf.writableRegion(1, 64, wbuf.getByteOrder()); //wrong!
     }
@@ -330,7 +330,7 @@ public class NativeWritableBufferImplTest {
     WritableBuffer mem = 
WritableMemory.allocate(memCapacity).asWritableBuffer();
     assertFalse(mem.isDirect());
     ResourceScope scope = ResourceScope.newConfinedScope();
-    WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+    WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, 1, scope, 
ByteOrder.nativeOrder(), memReqSvr);
     WritableBuffer wbuf = wmem.asWritableBuffer();
     assertTrue(wbuf.isDirect());
     wmem.close(); //immediate close
@@ -385,9 +385,9 @@ public class NativeWritableBufferImplTest {
     byte[] arr2 = new byte[] {0, 1, 2, 4};
     byte[] arr3 = new byte[] {0, 1, 2, 3, 4};
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem1 = WritableMemory.allocateDirect(4, scope, memReqSvr);
-      WritableMemory mem2 = WritableMemory.allocateDirect(4, scope, memReqSvr);
-      WritableMemory mem3 = WritableMemory.allocateDirect(5, scope, memReqSvr);
+      WritableMemory mem1 = WritableMemory.allocateDirect(4, 1, scope, 
ByteOrder.nativeOrder(), memReqSvr);
+      WritableMemory mem2 = WritableMemory.allocateDirect(4, 1, scope, 
ByteOrder.nativeOrder(), memReqSvr);
+      WritableMemory mem3 = WritableMemory.allocateDirect(5, 1, scope, 
ByteOrder.nativeOrder(), memReqSvr);
 
       mem1.putByteArray(0, arr1, 0, 4);
       mem2.putByteArray(0, arr2, 0, 4);
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java
 
b/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java
index 8e5e082..2ed8caa 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java
@@ -47,7 +47,7 @@ public class NativeWritableMemoryImplTest {
   public void checkNativeCapacityAndClose() throws Exception {
     int memCapacity = 64;
     ResourceScope scope = ResourceScope.newConfinedScope();
-    WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+    WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, 1, scope, 
ByteOrder.nativeOrder(), memReqSvr);
     assertEquals(memCapacity, wmem.getCapacity());
 
     wmem.close(); //intentional
@@ -188,7 +188,7 @@ public class NativeWritableMemoryImplTest {
   public void checkNativeBaseBound() throws Exception {
     int memCapacity = 64;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       wmem.toHexString("Force Assertion Error", memCapacity, 8, false);
     } catch (IllegalArgumentException e) {
       //ok
@@ -199,7 +199,7 @@ public class NativeWritableMemoryImplTest {
   public void checkNativeSrcArrayBound() throws Exception {
     long memCapacity = 64;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       byte[] srcArray = { 1, -2, 3, -4 };
       wmem.putByteArray(0L, srcArray, 0, 5);
     } catch (IndexOutOfBoundsException e) {
@@ -220,7 +220,7 @@ public class NativeWritableMemoryImplTest {
     int memCapacity = 64;
     int half = memCapacity/2;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       wmem.clear();
 
       for (int i=0; i<half; i++) { //fill first half
@@ -242,7 +242,7 @@ public class NativeWritableMemoryImplTest {
     int halfBytes = memCapacity / 2;
     int halfLongs = memCapLongs / 2;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       wmem.clear();
 
       for (int i=0; i < halfLongs; i++) {
@@ -261,7 +261,7 @@ public class NativeWritableMemoryImplTest {
   public void checkCopyWithinNativeSrcBound() throws Exception {
     int memCapacity = 64;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       wmem.copyTo(32, wmem, 32, 33);  //hit source bound check
       fail("Did Not Catch Assertion Error: source bound");
     }
@@ -274,7 +274,7 @@ public class NativeWritableMemoryImplTest {
   public void checkCopyWithinNativeDstBound() throws Exception {
     int memCapacity = 64;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       wmem.copyTo(0, wmem, 32, 33);  //hit dst bound check
       fail("Did Not Catch Assertion Error: dst bound");
     }
@@ -288,8 +288,8 @@ public class NativeWritableMemoryImplTest {
     int memCapacity = 64;
 
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory wmem1 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
-      WritableMemory wmem2 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory wmem1 = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
+      WritableMemory wmem2 = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
 
       for (int i=0; i < memCapacity; i++) {
         wmem1.putByte(i, (byte) i);
@@ -309,8 +309,8 @@ public class NativeWritableMemoryImplTest {
     int memCapLongs = memCapacity / 8;
 
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory wmem1 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
-      WritableMemory wmem2 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory wmem1 = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
+      WritableMemory wmem2 = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
 
       for (int i=0; i < memCapLongs; i++) {
         wmem1.putLong(i*8, i);
@@ -329,7 +329,7 @@ public class NativeWritableMemoryImplTest {
   public void checkCopyCrossNativeAndByteArray() throws Exception {
     int memCapacity = 64;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
 
       for (int i= 0; i < wmem.getCapacity(); i++) {
         wmem.putByte(i, (byte) i);
@@ -350,7 +350,7 @@ public class NativeWritableMemoryImplTest {
     int memCapacity = 128;
 
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory wmem1 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory wmem1 = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
 
       for (int i= 0; i < wmem1.getCapacity(); i++) {
         wmem1.putByte(i, (byte) i);
@@ -376,7 +376,7 @@ public class NativeWritableMemoryImplTest {
   public void checkCopyCrossNativeArrayAndHierarchicalRegions() throws 
Exception {
     int memCapacity = 64;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory wmem1 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory wmem1 = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
 
       for (int i= 0; i < wmem1.getCapacity(); i++) { //fill with numbers
         wmem1.putByte(i, (byte) i);
@@ -406,7 +406,7 @@ public class NativeWritableMemoryImplTest {
   public void checkRegionBounds() throws Exception {
     int memCapacity = 64;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       wmem.writableRegion(1, 64);
     }
   }
@@ -518,7 +518,7 @@ public class NativeWritableMemoryImplTest {
     WritableMemory mem = WritableMemory.allocate(memCapacity);
     assertFalse(mem.isDirect());
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory wmem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       assertTrue(wmem.isDirect());
     }
   }
@@ -579,9 +579,9 @@ public class NativeWritableMemoryImplTest {
     byte[] arr3 = new byte[] {0, 1, 2, 3, 4};
 
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem1 = WritableMemory.allocateDirect(4, scope, memReqSvr);
-      WritableMemory mem2 = WritableMemory.allocateDirect(4, scope, memReqSvr);
-      WritableMemory mem3 = WritableMemory.allocateDirect(5, scope, memReqSvr);
+      WritableMemory mem1 = WritableMemory.allocateDirect(4, 1, scope, 
ByteOrder.nativeOrder(), memReqSvr);
+      WritableMemory mem2 = WritableMemory.allocateDirect(4, 1, scope, 
ByteOrder.nativeOrder(), memReqSvr);
+      WritableMemory mem3 = WritableMemory.allocateDirect(5, 1, scope, 
ByteOrder.nativeOrder(), memReqSvr);
 
       mem1.putByteArray(0, arr1, 0, 4);
       mem2.putByteArray(0, arr2, 0, 4);
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java 
b/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java
index 962097d..6e6e771 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java
@@ -75,7 +75,7 @@ public class SpecificLeafTest {
   public void checkDirectLeafs() throws Exception {
     int bytes = 128;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory wmem = WritableMemory.allocateDirect(bytes, scope, 
memReqSvr);
+      WritableMemory wmem = WritableMemory.allocateDirect(bytes, 1, scope, 
ByteOrder.nativeOrder(), memReqSvr);
       assertFalse(((BaseStateImpl)wmem).isReadOnly());
       assertTrue(wmem.isDirect());
       assertFalse(wmem.isHeap());
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/WritableDirectCopyTest.java
 
b/src/test/java/org/apache/datasketches/memory/internal/WritableDirectCopyTest.java
index 0c3afab..1b024f5 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/WritableDirectCopyTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/WritableDirectCopyTest.java
@@ -22,6 +22,8 @@ package org.apache.datasketches.memory.internal;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.fail;
 
+import java.nio.ByteOrder;
+
 import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.MemoryRequestServer;
@@ -43,7 +45,7 @@ public class WritableDirectCopyTest {
     int memCapacity = 64;
     int half = memCapacity / 2;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       mem.clear();
 
       for (int i = 0; i < half; i++) { //fill first half
@@ -65,7 +67,7 @@ public class WritableDirectCopyTest {
     int halfBytes = memCapacity / 2;
     int halfLongs = memCapLongs / 2;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       mem.clear();
 
       for (int i = 0; i < halfLongs; i++) {
@@ -84,7 +86,7 @@ public class WritableDirectCopyTest {
   public void checkCopyWithinNativeOverlap() throws Exception {
     int memCapacity = 64;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       mem.clear();
       //println(mem.toHexString("Clear 64", 0, memCapacity));
 
@@ -100,7 +102,7 @@ public class WritableDirectCopyTest {
   public void checkCopyWithinNativeSrcBound() throws Exception {
     int memCapacity = 64;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       mem.copyTo(32, mem, 32, 33);  //hit source bound check
       fail("Did Not Catch Assertion Error: source bound");
     } catch (IndexOutOfBoundsException e) {
@@ -112,7 +114,7 @@ public class WritableDirectCopyTest {
   public void checkCopyWithinNativeDstBound() throws Exception {
     int memCapacity = 64;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory mem = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
       mem.copyTo(0, mem, 32, 33);  //hit dst bound check
       fail("Did Not Catch Assertion Error: dst bound");
     } catch (IndexOutOfBoundsException e) {
@@ -125,8 +127,8 @@ public class WritableDirectCopyTest {
     int memCapacity = 64;
 
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
-      WritableMemory mem2 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
+      WritableMemory mem2 = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
 
       for (int i = 0; i < memCapacity; i++) {
         mem1.putByte(i, (byte) i);
@@ -146,8 +148,8 @@ public class WritableDirectCopyTest {
     int memCapLongs = memCapacity / 8;
 
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
-      WritableMemory mem2 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
+      WritableMemory mem2 = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
 
       for (int i = 0; i < memCapLongs; i++) {
         mem1.putLong(i * 8, i);
@@ -166,7 +168,7 @@ public class WritableDirectCopyTest {
   public void checkCopyCrossNativeAndByteArray() throws Exception {
     int memCapacity = 64;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
 
       for (int i = 0; i < mem1.getCapacity(); i++) {
         mem1.putByte(i, (byte) i);
@@ -187,7 +189,7 @@ public class WritableDirectCopyTest {
     int memCapacity = 128;
 
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
 
       for (int i = 0; i < mem1.getCapacity(); i++) {
         mem1.putByte(i, (byte) i);
@@ -213,7 +215,7 @@ public class WritableDirectCopyTest {
   public void checkCopyCrossNativeArrayAndHierarchicalRegions() throws 
Exception {
     int memCapacity = 64;
     try (ResourceScope scope = ResourceScope.newConfinedScope()) {
-      WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, scope, 
memReqSvr);
+      WritableMemory mem1 = WritableMemory.allocateDirect(memCapacity, 1, 
scope, ByteOrder.nativeOrder(), memReqSvr);
 
       for (int i = 0; i < mem1.getCapacity(); i++) { //fill with numbers
         mem1.putByte(i, (byte) i);
diff --git 
a/src/test/java/org/apache/datasketches/memory/internal/ZeroCapacityTest.java 
b/src/test/java/org/apache/datasketches/memory/internal/ZeroCapacityTest.java
index e54b6d9..3db859a 100644
--- 
a/src/test/java/org/apache/datasketches/memory/internal/ZeroCapacityTest.java
+++ 
b/src/test/java/org/apache/datasketches/memory/internal/ZeroCapacityTest.java
@@ -22,6 +22,7 @@ package org.apache.datasketches.memory.internal;
 import static org.testng.Assert.assertEquals;
 
 import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
 
 import org.apache.datasketches.memory.BaseState;
 import org.apache.datasketches.memory.Memory;
@@ -51,7 +52,7 @@ public class ZeroCapacityTest {
     WritableMemory nullMem = null;
     ResourceScope scope = ResourceScope.newConfinedScope();
     try { //Invalid allocation size : 0
-      nullMem = WritableMemory.allocateDirect(0, scope, memReqSvr);
+      nullMem = WritableMemory.allocateDirect(0, 1, scope, 
ByteOrder.nativeOrder(), memReqSvr);
       Assert.fail();
     } catch (IllegalArgumentException ignore) {
       if (nullMem != null) {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to