You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by le...@apache.org on 2023/01/13 21:57:14 UTC

[datasketches-memory] branch master_tempfix created (now d54aceb)

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

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


      at d54aceb  Interim - passes all tests, almost done.

This branch includes the following new commits:

     new 51a93af  Got Heap working, but Map, Direct and BB still have errors.
     new 1d71786  Interim -- still not working.
     new d54aceb  Interim - passes all tests, almost done.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org


[datasketches-memory] 01/03: Got Heap working, but Map, Direct and BB still have errors.

Posted by le...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 51a93aff3e657979a159c6edaa26808d5da79ed3
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Sun Jan 8 15:56:34 2023 -0800

    Got Heap working, but Map, Direct and BB still have errors.
---
 .../org/apache/datasketches/memory/BaseState.java  | 174 ++++----
 .../apache/datasketches/memory/MurmurHash3v2.java  |   2 +-
 .../apache/datasketches/memory/WritableMemory.java |   6 +-
 .../memory/internal/BaseBufferImpl.java            |   8 +-
 .../memory/internal/BaseStateImpl.java             | 441 ++++++++++-----------
 .../memory/internal/BaseWritableBufferImpl.java    |  15 +-
 .../memory/internal/BaseWritableMemoryImpl.java    |  47 ++-
 .../internal/HeapNonNativeWritableBufferImpl.java  | 108 +++--
 .../internal/HeapNonNativeWritableMemoryImpl.java  |  91 +++--
 .../memory/internal/HeapWritableBufferImpl.java    | 108 +++--
 .../memory/internal/HeapWritableMemoryImpl.java    |  93 +++--
 .../memory/internal/MapWritableMemoryImpl.java     |   6 +-
 .../memory/internal/NativeWritableBufferImpl.java  |   7 +-
 .../memory/internal/NativeWritableMemoryImpl.java  |   7 +-
 .../internal/NonNativeWritableBufferImpl.java      |   7 +-
 .../internal/NonNativeWritableMemoryImpl.java      |   7 +-
 .../internal/AllocateDirectMapMemoryTest.java      |  35 +-
 .../internal/NativeWritableBufferImplTest.java     |   1 -
 .../internal/NativeWritableMemoryImplTest.java     |   4 +-
 .../memory/internal/SpecificLeafTest.java          |  89 +++--
 20 files changed, 711 insertions(+), 545 deletions(-)

diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseState.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseState.java
index 2ec75cb..2da19c4 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseState.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseState.java
@@ -36,23 +36,49 @@ public interface BaseState {
    */
   static final MemoryRequestServer defaultMemReqSvr = null; //new DefaultMemoryRequestServer();
 
-  //Byte Order Related
+  //Monitoring
 
   /**
-   * Gets the current Type ByteOrder.
-   * This may be different from the ByteOrder of the backing resource and of the Native Byte Order.
-   * @return the current Type ByteOrder.
+   * Gets the current size of active direct memory allocated.
+   * @return the current size of active direct memory allocated.
    */
-  ByteOrder getTypeByteOrder();
+  static long getCurrentDirectMemoryAllocated() {
+    return BaseStateImpl.getCurrentDirectMemoryAllocated();
+  }
 
   /**
-   * Returns true if the Native ByteOrder is the same as the ByteOrder of the
-   * current Buffer or Memory and the same ByteOrder as the given byteOrder.
-   * @param byteOrder the given ByteOrder
-   * @return true if the Native ByteOrder is the same as the ByteOrder of the
-   * current Buffer or Memory and the same ByteOrder as the given byteOrder.
+   * Gets the current number of active direct memory allocations.
+   * @return the current number of active direct memory allocations.
    */
-  boolean isByteOrderCompatible(ByteOrder byteOrder);
+  static long getCurrentDirectMemoryAllocations() {
+    return BaseStateImpl.getCurrentDirectMemoryAllocations();
+  }
+
+  /**
+   * Gets the current size of active direct memory map allocated.
+   * @return the current size of active direct memory map allocated.
+   */
+  static long getCurrentDirectMemoryMapAllocated() {
+    return BaseStateImpl.getCurrentDirectMemoryMapAllocated();
+  }
+
+  /**
+   * Gets the current number of active direct memory map allocations.
+   * @return the current number of active direct memory map allocations.
+   */
+  static long getCurrentDirectMemoryMapAllocations() {
+    return BaseStateImpl.getCurrentDirectMemoryMapAllocations();
+  }
+  //End Monitoring
+
+  /**
+   * Checks that the specified range of bytes is within bounds of this object, throws
+   * {@link IllegalArgumentException} if it's not: i. e. if offsetBytes &lt; 0, or length &lt; 0,
+   * or offsetBytes + length &gt; {@link #getCapacity()}.
+   * @param offsetBytes the given offset in bytes of this object
+   * @param lengthBytes the given length in bytes of this object
+   */
+  void checkValidAndBounds(long offsetBytes, long lengthBytes);
 
   /**
    * Returns true if the given object is an instance of this class and has equal data contents.
@@ -99,18 +125,21 @@ public interface BaseState {
 
   /**
    * Gets the cumulative offset in bytes of this object from the backing resource including the given
-   * offsetBytes. This offset may also include other offset components such as the native off-heap
-   * memory address, DirectByteBuffer split offsets, region offsets, and unsafe arrayBaseOffsets.
+   * localOffsetBytes. This offset may also include other offset components such as the native off-heap
+   * memory address, DirectByteBuffer split offsets, region offsets, and object arrayBaseOffsets.
    *
-   * @param offsetBytes offset to be added to the cumulative offset.
+   * @param localOffsetBytes offset to be added to the cumulative offset.
    * @return the cumulative offset in bytes of this object from the backing resource including the
    * given offsetBytes.
    */
-  long getCumulativeOffset(long offsetBytes);
+  default long getCumulativeOffset(long localOffsetBytes) {
+    return getCumulativeOffset() + localOffsetBytes;
+  }
 
   /**
    * Returns the offset of address zero of this object relative to the address zero of the
    * backing resource but not including the size of any Java object header.
+   * This is only used when moving directly across to Memory, Buffer or Buffer duplicate.
    * @return the offset of address zero of this object relative to the address zero of the
    * backing resource but not including the size of any Java object header.
    */
@@ -125,7 +154,16 @@ public interface BaseState {
    * backing resource plus the given offsetBytes but not including the size of any Java object
    * header.
    */
-  long getRegionOffset(long offsetBytes);
+  default long getRegionOffset(long offsetBytes) {
+    return getRegionOffset() + offsetBytes;
+  }
+
+  /**
+   * Gets the current Type ByteOrder.
+   * This may be different from the ByteOrder of the backing resource and of the Native Byte Order.
+   * @return the current Type ByteOrder.
+   */
+  ByteOrder getTypeByteOrder();
 
   /**
    * Returns true if this object is backed by an on-heap primitive array
@@ -133,6 +171,12 @@ public interface BaseState {
    */
   boolean hasArray();
 
+  /**
+   * Returns true if this Memory is backed by a ByteBuffer.
+   * @return true if this Memory is backed by a ByteBuffer.
+   */
+  boolean hasByteBuffer();
+
   /**
    * Returns the hashCode of this object.
    *
@@ -149,32 +193,13 @@ public interface BaseState {
   int hashCode();
 
   /**
-   * Returns the 64-bit hash of the sequence of bytes in this object specified by
-   * <i>offsetBytes</i>, <i>lengthBytes</i> and a <i>seed</i>.  Note that the sequence of bytes is
-   * always processed in the same order independent of endianness.
-   *
-   * @param offsetBytes the given offset in bytes to the first byte of the byte sequence.
-   * @param lengthBytes the given length in bytes of the byte sequence.
-   * @param seed the given long seed.
-   * @return the 64-bit hash of the sequence of bytes in this object specified by
-   * <i>offsetBytes</i> and <i>lengthBytes</i>.
-   */
-  long xxHash64(long offsetBytes, long lengthBytes, long seed);
-
-  /**
-   * Returns a 64-bit hash from a single long. This method has been optimized for speed when only
-   * a single hash of a long is required.
-   * @param in A long.
-   * @param seed A long valued seed.
-   * @return the hash.
-   */
-  long xxHash64(long in, long seed);
-
-  /**
-   * Returns true if this Memory is backed by a ByteBuffer.
-   * @return true if this Memory is backed by a ByteBuffer.
+   * Returns true if the Native ByteOrder is the same as the ByteOrder of the
+   * current Buffer or Memory and the same ByteOrder as the given byteOrder.
+   * @param byteOrder the given ByteOrder
+   * @return true if the Native ByteOrder is the same as the ByteOrder of the
+   * current Buffer or Memory and the same ByteOrder as the given byteOrder.
    */
-  boolean hasByteBuffer();
+  boolean isByteOrderCompatible(ByteOrder byteOrder);
 
   /**
    * Returns true if the backing resource is direct (off-heap) memory.
@@ -206,51 +231,6 @@ public interface BaseState {
    */
   boolean isValid();
 
-  /**
-   * Checks that the specified range of bytes is within bounds of this object, throws
-   * {@link IllegalArgumentException} if it's not: i. e. if offsetBytes &lt; 0, or length &lt; 0,
-   * or offsetBytes + length &gt; {@link #getCapacity()}.
-   * @param offsetBytes the given offset in bytes of this object
-   * @param lengthBytes the given length in bytes of this object
-   */
-  void checkValidAndBounds(long offsetBytes, long lengthBytes);
-
-  //Monitoring
-
-  /**
-   * Gets the current number of active direct memory allocations.
-   * @return the current number of active direct memory allocations.
-   */
-  static long getCurrentDirectMemoryAllocations() {
-    return BaseStateImpl.getCurrentDirectMemoryAllocations();
-  }
-
-  /**
-   * Gets the current size of active direct memory allocated.
-   * @return the current size of active direct memory allocated.
-   */
-  static long getCurrentDirectMemoryAllocated() {
-    return BaseStateImpl.getCurrentDirectMemoryAllocated();
-  }
-
-  /**
-   * Gets the current number of active direct memory map allocations.
-   * @return the current number of active direct memory map allocations.
-   */
-  static long getCurrentDirectMemoryMapAllocations() {
-    return BaseStateImpl.getCurrentDirectMemoryMapAllocations();
-  }
-
-  /**
-   * Gets the current size of active direct memory map allocated.
-   * @return the current size of active direct memory map allocated.
-   */
-  static long getCurrentDirectMemoryMapAllocated() {
-    return BaseStateImpl.getCurrentDirectMemoryMapAllocated();
-  }
-
-  //TO STRING
-
   /**
    * Returns a formatted hex string of a range of this object.
    * Used primarily for testing.
@@ -261,4 +241,26 @@ public interface BaseState {
    */
   String toHexString(String header, long offsetBytes, int lengthBytes);
 
+  /**
+   * Returns the 64-bit hash of the sequence of bytes in this object specified by
+   * <i>offsetBytes</i>, <i>lengthBytes</i> and a <i>seed</i>.  Note that the sequence of bytes is
+   * always processed in the same order independent of endianness.
+   *
+   * @param offsetBytes the given offset in bytes to the first byte of the byte sequence.
+   * @param lengthBytes the given length in bytes of the byte sequence.
+   * @param seed the given long seed.
+   * @return the 64-bit hash of the sequence of bytes in this object specified by
+   * <i>offsetBytes</i> and <i>lengthBytes</i>.
+   */
+  long xxHash64(long offsetBytes, long lengthBytes, long seed);
+
+  /**
+   * Returns a 64-bit hash from a single long. This method has been optimized for speed when only
+   * a single hash of a long is required.
+   * @param in A long.
+   * @param seed A long valued seed.
+   * @return the hash.
+   */
+  long xxHash64(long in, long seed);
+
 }
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MurmurHash3v2.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MurmurHash3v2.java
index 9c5a35b..67c4830 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MurmurHash3v2.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MurmurHash3v2.java
@@ -177,7 +177,7 @@ public final class MurmurHash3v2 {
     if (uObj == null) {
       throw new IllegalArgumentException("The backing resource of input mem is not on-heap.");
     }
-    long cumOff = mem.getCumulativeOffset() + offsetBytes;
+    long cumOff = mem.getCumulativeOffset(offsetBytes);
 
     long h1 = seed;
     long h2 = seed;
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMemory.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMemory.java
index cdc1635..feacb1b 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMemory.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMemory.java
@@ -162,12 +162,12 @@ public interface WritableMemory extends Memory {
    * <li>Returned object's capacity = <i>capacityBytes</i></li>
    * </ul>
    *
-   * @param offsetBytes the starting offset with respect to this object. It must be &ge; 0.
+   * @param regionOffsetBytes the starting offset with respect to this object. It must be &ge; 0.
    * @param capacityBytes the capacity of the returned object in bytes. It must be &ge; 0.
    * @return a new <i>WritableMemory</i> representing the defined writable region.
    */
-  default WritableMemory writableRegion(long offsetBytes, long capacityBytes) {
-    return writableRegion(offsetBytes, capacityBytes, getTypeByteOrder());
+  default WritableMemory writableRegion(long regionOffsetBytes, long capacityBytes) {
+    return writableRegion(regionOffsetBytes, capacityBytes, getTypeByteOrder());
   }
 
   /**
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseBufferImpl.java
index 7bc1340..0e815df 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseBufferImpl.java
@@ -45,13 +45,13 @@ public abstract class BaseBufferImpl extends BaseStateImpl implements BaseBuffer
   private long pos = 0;
   private long end;
 
-  //Pass-through ctor
-  BaseBufferImpl(final Object unsafeObj, final long nativeBaseOffset,
-      final long regionOffset, final long capacityBytes) {
-    super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes);
+  //Pass-through constructor
+  BaseBufferImpl(final long capacityBytes) {
+    super();
     capacity = end = capacityBytes;
   }
 
+
   @Override
   public final BaseBufferImpl incrementPosition(final long increment) {
     incrementAndAssertPositionForRead(pos, increment);
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
index 42062c1..8c64e58 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
@@ -50,6 +50,7 @@ public abstract class BaseStateImpl implements BaseState {
   //class type IDs. Do not change the bit orders
   //The first 3 bits are set dynamically
   // 0000 0XXX
+  static final int WRITABLE = 0;
   static final int READONLY = 1;
   static final int REGION = 2;
   static final int DUPLICATE = 4;
@@ -59,7 +60,6 @@ public abstract class BaseStateImpl implements BaseState {
   static final int HEAP = 0;
   static final int DIRECT = 1 << 3;
   static final int MAP = 2 << 3;
-  static final int BYTEBUF = 3 << 3;
 
   // 00X0 0000
   static final int NATIVE = 0;
@@ -69,57 +69,54 @@ public abstract class BaseStateImpl implements BaseState {
   static final int MEMORY = 0;
   static final int BUFFER = 1 << 6;
 
-  private final long capacityBytes_;
-
+  // X000 0000
+  static final int BYTEBUF = 1 << 7;
   /**
-   * This becomes the base offset used by all Unsafe calls. It is cumulative in that in includes
-   * all offsets from regions, user-defined offsets when creating MemoryImpl, and the array object
-   * header offset when creating MemoryImpl from primitive arrays.
+   * The root of the Memory inheritance hierarchy
    */
-  private final long cumBaseOffset_;
+  BaseStateImpl() { }
 
-  /**
-   *
-   * @param unsafeObj The primitive backing array. It may be null. Used by Unsafe calls.
-   * @param nativeBaseOffset The off-heap memory address including DirectByteBuffer split offsets.
-   * @param regionOffset This offset defines address zero of this object (usually a region)
-   * relative to address zero of the backing resource. It is used to compute cumBaseOffset.
-   * This will be loaded from heap ByteBuffers, which have a similar field used for slices.
-   * It is used by region() and writableRegion().
-   * This offset does not include the size of an object array header, if there is one.
-   * @param capacityBytes the capacity of this object. Used by all methods when checking bounds.
-   */
-  BaseStateImpl(final Object unsafeObj, final long nativeBaseOffset, final long regionOffset,
-      final long capacityBytes) {
-    capacityBytes_ = capacityBytes;
-    cumBaseOffset_ = regionOffset + (unsafeObj == null
-        ? nativeBaseOffset
-        : UnsafeUtil.getArrayBaseOffset(unsafeObj.getClass()));
+  final void assertValid() {
+    assert isValid() : "MemoryImpl not valid.";
   }
 
-  //Byte Order Related
+  final void assertValidAndBoundsForRead(final long offsetBytes, final long lengthBytes) {
+    assertValid();
+    // capacityBytes_ is intentionally read directly instead of calling getCapacity()
+    // because the later can make JVM to not inline the assert code path (and entirely remove it)
+    // even though it does nothing in production code path.
+    assertBounds(offsetBytes, lengthBytes, getCapacity());
+  }
 
-  @Override
-  public final ByteOrder getTypeByteOrder() {
-    return isNonNativeType() ? Util.NON_NATIVE_BYTE_ORDER : ByteOrder.nativeOrder();
+  final void assertValidAndBoundsForWrite(final long offsetBytes, final long lengthBytes) {
+    assertValid();
+    // capacityBytes_ is intentionally read directly instead of calling getCapacity()
+    // because the later can make JVM to not inline the assert code path (and entirely remove it)
+    // even though it does nothing in production code path.
+    assertBounds(offsetBytes, lengthBytes, getCapacity());
+    assert !isReadOnly() : "MemoryImpl is read-only.";
   }
 
-  /**
-   * Returns true if the given byteOrder is the same as the native byte order.
-   * @param byteOrder the given byte order
-   * @return true if the given byteOrder is the same as the native byte order.
-   */
-  public static boolean isNativeByteOrder(final ByteOrder byteOrder) {
-    if (byteOrder == null) {
-      throw new IllegalArgumentException("ByteOrder parameter cannot be null.");
+  void checkValid() {
+    if (!isValid()) {
+      throw new IllegalStateException("MemoryImpl not valid.");
     }
-    return ByteOrder.nativeOrder() == byteOrder;
   }
 
   @Override
-  public final boolean isByteOrderCompatible(final ByteOrder byteOrder) {
-    final ByteOrder typeBO = getTypeByteOrder();
-    return typeBO == ByteOrder.nativeOrder() && typeBO == byteOrder;
+  public final void checkValidAndBounds(final long offsetBytes, final long lengthBytes) {
+    checkValid();
+    //read capacityBytes_ directly to eliminate extra checkValid() call
+    checkBounds(offsetBytes, lengthBytes, getCapacity());
+  }
+
+  final void checkValidAndBoundsForWrite(final long offsetBytes, final long lengthBytes) {
+    checkValid();
+    //read capacityBytes_ directly to eliminate extra checkValid() call
+    checkBounds(offsetBytes, lengthBytes, getCapacity());
+    if (isReadOnly()) {
+      throw new ReadOnlyException("MemoryImpl is read-only.");
+    }
   }
 
   @Override
@@ -144,44 +141,51 @@ public abstract class BaseStateImpl implements BaseState {
     return null;
   }
 
-  @Override
-  public final long getCapacity() {
-    assertValid();
-    return capacityBytes_;
+  //MONITORING
+
+  /**
+   * Gets the current size of active direct memory allocated.
+   * @return the current size of active direct memory allocated.
+   */
+  public static final long getCurrentDirectMemoryAllocated() {
+    return BaseStateImpl.currentDirectMemoryAllocated_.get();
   }
 
-  @Override
-  public final long getCumulativeOffset() {
-    assertValid();
-    return cumBaseOffset_;
+  /**
+   * Gets the current number of active direct memory allocations.
+   * @return the current number of active direct memory allocations.
+   */
+  public static final long getCurrentDirectMemoryAllocations() {
+    return BaseStateImpl.currentDirectMemoryAllocations_.get();
   }
 
-  @Override
-  public final long getCumulativeOffset(final long offsetBytes) {
-    assertValid();
-    return cumBaseOffset_ + offsetBytes;
+  /**
+   * Gets the current size of active direct memory map allocated.
+   * @return the current size of active direct memory map allocated.
+   */
+  public static final long getCurrentDirectMemoryMapAllocated() {
+    return BaseStateImpl.currentDirectMemoryMapAllocated_.get();
+  }
+
+  /**
+   * Gets the current number of active direct memory map allocations.
+   * @return the current number of active direct memory map allocations.
+   */
+  public static final long getCurrentDirectMemoryMapAllocations() {
+    return BaseStateImpl.currentDirectMemoryMapAllocations_.get();
   }
+  //END monitoring
 
   //Documented in WritableMemory and WritableBuffer interfaces.
   //Implemented in the Leaf nodes; Required here by toHex(...).
   abstract MemoryRequestServer getMemoryRequestServer();
 
   //Overridden by ByteBuffer, Direct and Map leafs
-  long getNativeBaseOffset() {
-    return 0;
-  }
-
-  @Override
-  public final long getRegionOffset() {
-    final Object unsafeObj = getUnsafeObject();
-    return unsafeObj == null
-        ? cumBaseOffset_ - getNativeBaseOffset()
-        : cumBaseOffset_ - UnsafeUtil.getArrayBaseOffset(unsafeObj.getClass());
-  }
+  abstract long getNativeBaseOffset();
 
   @Override
-  public final long getRegionOffset(final long offsetBytes) {
-    return getRegionOffset() + offsetBytes;
+  public final ByteOrder getTypeByteOrder() {
+    return isNonNativeType(getTypeId()) ? Util.NON_NATIVE_BYTE_ORDER : ByteOrder.nativeOrder();
   }
 
   //Overridden by all leafs
@@ -193,6 +197,12 @@ public abstract class BaseStateImpl implements BaseState {
     return null;
   }
 
+  @Override
+  public final boolean hasByteBuffer() {
+    assertValid();
+    return getByteBuffer() != null;
+  }
+
   @Override
   public final boolean hasArray() {
     assertValid();
@@ -201,24 +211,21 @@ public abstract class BaseStateImpl implements BaseState {
 
   @Override
   public final int hashCode() {
-    return (int) xxHash64(0, capacityBytes_, 0); //xxHash64() calls checkValid()
+    return (int) xxHash64(0, getCapacity(), 0); //xxHash64() calls checkValid()
   }
 
-  @Override
-  public final long xxHash64(final long offsetBytes, final long lengthBytes, final long seed) {
-    checkValid();
-    return XxHash64.hash(getUnsafeObject(), cumBaseOffset_ + offsetBytes, lengthBytes, seed);
+  final boolean isByteBufferType(final int typeId) {
+    return (typeId & BYTEBUF) > 0;
   }
 
   @Override
-  public final long xxHash64(final long in, final long seed) {
-    return XxHash64.hash(in, seed);
+  public final boolean isByteOrderCompatible(final ByteOrder byteOrder) {
+    final ByteOrder typeBO = getTypeByteOrder();
+    return typeBO == ByteOrder.nativeOrder() && typeBO == byteOrder;
   }
 
-  @Override
-  public final boolean hasByteBuffer() {
-    assertValid();
-    return getByteBuffer() != null;
+  final boolean isBufferType(final int typeId) {
+    return (typeId & BUFFER) > 0;
   }
 
   @Override
@@ -226,174 +233,84 @@ public abstract class BaseStateImpl implements BaseState {
     return getUnsafeObject() == null;
   }
 
-  @Override
-  public final boolean isReadOnly() {
-    assertValid();
-    return isReadOnlyType();
+  final boolean isDirectType(final int typeId) {
+    return (typeId & (MAP | DIRECT)) > 0;
   }
 
-  @Override
-  public final boolean isSameResource(final Object that) {
-    checkValid();
-    if (that == null) { return false; }
-    final BaseStateImpl that1 = (BaseStateImpl) that;
-    that1.checkValid();
-    if (this == that1) { return true; }
-
-    return cumBaseOffset_ == that1.cumBaseOffset_
-            && capacityBytes_ == that1.capacityBytes_
-            && getUnsafeObject() == that1.getUnsafeObject()
-            && getByteBuffer() == that1.getByteBuffer();
+  final boolean isDuplicateType(final int typeId) {
+    return (typeId & DUPLICATE) > 0;
   }
 
-  //Overridden by Direct and Map leafs
-  @Override
-  public boolean isValid() {
-    return true;
+  final boolean isHeapType(final int typeId) {
+    return (typeId & (MAP | DIRECT)) == 0;
   }
 
-  //ASSERTS AND CHECKS
-  final void assertValid() {
-    assert isValid() : "MemoryImpl not valid.";
+  final boolean isMapType(final int typeId) { //not used
+    return (typeId & MAP) > 0;
   }
 
-  void checkValid() {
-    if (!isValid()) {
-      throw new IllegalStateException("MemoryImpl not valid.");
-    }
+  final boolean isMemoryType(final int typeId) { //not used
+    return (typeId & BUFFER) == 0;
   }
 
-  final void assertValidAndBoundsForRead(final long offsetBytes, final long lengthBytes) {
-    assertValid();
-    // capacityBytes_ is intentionally read directly instead of calling getCapacity()
-    // because the later can make JVM to not inline the assert code path (and entirely remove it)
-    // even though it does nothing in production code path.
-    assertBounds(offsetBytes, lengthBytes, capacityBytes_);
+  final boolean isNativeType(final int typeId) { //not used
+    return (typeId & NONNATIVE) == 0;
   }
 
-  final void assertValidAndBoundsForWrite(final long offsetBytes, final long lengthBytes) {
-    assertValid();
-    // capacityBytes_ is intentionally read directly instead of calling getCapacity()
-    // because the later can make JVM to not inline the assert code path (and entirely remove it)
-    // even though it does nothing in production code path.
-    assertBounds(offsetBytes, lengthBytes, capacityBytes_);
-    assert !isReadOnly() : "MemoryImpl is read-only.";
+  final boolean isNonNativeType(final int typeId) {
+    return (typeId & NONNATIVE) > 0;
   }
 
   @Override
-  public final void checkValidAndBounds(final long offsetBytes, final long lengthBytes) {
-    checkValid();
-    //read capacityBytes_ directly to eliminate extra checkValid() call
-    checkBounds(offsetBytes, lengthBytes, capacityBytes_);
-  }
-
-  final void checkValidAndBoundsForWrite(final long offsetBytes, final long lengthBytes) {
-    checkValid();
-    //read capacityBytes_ directly to eliminate extra checkValid() call
-    checkBounds(offsetBytes, lengthBytes, capacityBytes_);
-    if (isReadOnly()) {
-      throw new ReadOnlyException("MemoryImpl is read-only.");
-    }
+  public final boolean isReadOnly() {
+    assertValid();
+    return isReadOnlyType(getTypeId());
   }
 
-  //TYPE ID Management
-  final boolean isReadOnlyType() {
-    return (getTypeId() & READONLY) > 0;
+  final boolean isReadOnlyType(final int typeId) {
+    return (typeId & READONLY) > 0;
   }
 
-  final static byte setReadOnlyType(final byte type, final boolean readOnly) {
-    return (byte)((type & ~1) | (readOnly ? READONLY : 0));
+  final boolean isRegionType(final int typeId) {
+    return (typeId & REGION) > 0;
   }
 
-  final boolean isRegionType() {
-    return (getTypeId() & REGION) > 0;
+  final boolean isWritableType(final int typeId) { //not used
+    return (typeId & READONLY) == 0;
   }
 
-  final boolean isDuplicateType() {
-    return (getTypeId() & DUPLICATE) > 0;
-  }
+  final static int removeNnBuf(final int typeId) { return typeId & ~NONNATIVE & ~BUFFER; }
 
-  //The following are set by the leaf nodes
-  final boolean isBufferType() {
-    return (getTypeId() & BUFFER) > 0;
+  final static int setReadOnlyType(final int typeId, final boolean readOnly) {
+    return readOnly ? typeId | READONLY : typeId & ~READONLY;
   }
 
-  final boolean isNonNativeType() {
-    return (getTypeId() & NONNATIVE) > 0;
-  }
+  final
 
-  final boolean isHeapType() {
-    return (getTypeId() >>> 3 & 3) == 0;
-  }
+  @Override
+  public boolean isSameResource(final Object that) {
+    checkValid();
+    if (that == null) { return false; }
+    final BaseStateImpl that1 = (BaseStateImpl) that;
+    that1.checkValid();
+    if (this == that1) { return true; }
 
-  final boolean isDirectType() {
-    return (getTypeId() >>> 3 & 3) == 1;
+    return getCumulativeOffset(0) == that1.getCumulativeOffset(0)
+            && getCapacity() == that1.getCapacity()
+            && getUnsafeObject() == that1.getUnsafeObject()
+            && getByteBuffer() == that1.getByteBuffer();
   }
 
-  final boolean isMapType() {
-    return (getTypeId() >>> 3 & 3) == 2;
+  //Overridden by Direct and Map leafs
+  @Override
+  public boolean isValid() {
+    return true;
   }
 
-  final boolean isBBType() {
-    return (getTypeId() >>> 3 & 3) == 3;
-  }
+  //REACHABILITY FENCE
+  static void reachabilityFence(final Object obj) { }
 
   //TO STRING
-  /**
-   * Decodes the resource type. This is primarily for debugging.
-   * @param typeId the given typeId
-   * @return a human readable string.
-   */
-  public static final String typeDecode(final int typeId) {
-    final StringBuilder sb = new StringBuilder();
-    final int group1 = typeId & 0x7;
-    switch (group1) {
-      case 1 : sb.append("ReadOnly, "); break;
-      case 2 : sb.append("Region, "); break;
-      case 3 : sb.append("ReadOnly Region, "); break;
-      case 4 : sb.append("Duplicate, "); break;
-      case 5 : sb.append("ReadOnly Duplicate, "); break;
-      case 6 : sb.append("Region Duplicate, "); break;
-      case 7 : sb.append("ReadOnly Region Duplicate, "); break;
-      default: break;
-    }
-    final int group2 = (typeId >>> 3) & 0x3;
-    switch (group2) {
-      case 0 : sb.append("Heap, "); break;
-      case 1 : sb.append("Direct, "); break;
-      case 2 : sb.append("Map, "); break;
-      case 3 : sb.append("ByteBuffer, "); break;
-      default: break;
-    }
-    final int group3 = (typeId >>> 5) & 0x1;
-    switch (group3) {
-      case 0 : sb.append("Native, "); break;
-      case 1 : sb.append("NonNative, "); break;
-      default: break;
-    }
-    final int group4 = (typeId >>> 6) & 0x1;
-    switch (group4) {
-      case 0 : sb.append("Memory"); break;
-      case 1 : sb.append("Buffer"); break;
-      default: break;
-    }
-    return sb.toString();
-  }
-
-  @Override
-  public final String toHexString(final String header, final long offsetBytes,
-      final int lengthBytes) {
-    checkValid();
-    final String klass = this.getClass().getSimpleName();
-    final String s1 = String.format("(..., %d, %d)", offsetBytes, lengthBytes);
-    final long hcode = hashCode() & 0XFFFFFFFFL;
-    final String call = ".toHexString" + s1 + ", hashCode: " + hcode;
-    final StringBuilder sb = new StringBuilder();
-    sb.append("### ").append(klass).append(" SUMMARY ###").append(LS);
-    sb.append("Header Comment      : ").append(header).append(LS);
-    sb.append("Call Parameters     : ").append(call);
-    return toHex(this, sb.toString(), offsetBytes, lengthBytes);
-  }
 
   /**
    * Returns a formatted hex string of an area of this object.
@@ -426,7 +343,7 @@ public abstract class BaseStateImpl implements BaseState {
     final String memReqStr = memReqSvr != null
         ? memReqSvr.getClass().getSimpleName() + ", " + (memReqSvr.hashCode() & 0XFFFFFFFFL)
         : "null";
-    final long cumBaseOffset = state.getCumulativeOffset();
+    final long cumBaseOffset = state.getCumulativeOffset(0);
     sb.append(preamble).append(LS);
     sb.append("UnsafeObj, hashCode : ").append(uObjStr).append(LS);
     sb.append("UnsafeObjHeader     : ").append(uObjHeader).append(LS);
@@ -455,41 +372,91 @@ public abstract class BaseStateImpl implements BaseState {
     return sb.toString();
   }
 
-  //MONITORING
-
-  /**
-   * Gets the current number of active direct memory allocations.
-   * @return the current number of active direct memory allocations.
-   */
-  public static final long getCurrentDirectMemoryAllocations() {
-    return BaseStateImpl.currentDirectMemoryAllocations_.get();
+  @Override
+  public final String toHexString(final String header, final long offsetBytes,
+      final int lengthBytes) {
+    checkValid();
+    final String klass = this.getClass().getSimpleName();
+    final String s1 = String.format("(..., %d, %d)", offsetBytes, lengthBytes);
+    final long hcode = hashCode() & 0XFFFFFFFFL;
+    final String call = ".toHexString" + s1 + ", hashCode: " + hcode;
+    final StringBuilder sb = new StringBuilder();
+    sb.append("### ").append(klass).append(" SUMMARY ###").append(LS);
+    sb.append("Header Comment      : ").append(header).append(LS);
+    sb.append("Call Parameters     : ").append(call);
+    return toHex(this, sb.toString(), offsetBytes, lengthBytes);
   }
 
   /**
-   * Gets the current size of active direct memory allocated.
-   * @return the current size of active direct memory allocated.
+   * Decodes the resource type. This is primarily for debugging.
+   * @param typeId the given typeId
+   * @return a human readable string.
    */
-  public static final long getCurrentDirectMemoryAllocated() {
-    return BaseStateImpl.currentDirectMemoryAllocated_.get();
+  public static final String typeDecode(final int typeId) {
+    final StringBuilder sb = new StringBuilder();
+    final int group1 = typeId & 0x7;
+    switch (group1) {
+      case 1 : sb.append("ReadOnly, "); break;
+      case 2 : sb.append("Region, "); break;
+      case 3 : sb.append("ReadOnly Region, "); break;
+      case 4 : sb.append("Duplicate, "); break;
+      case 5 : sb.append("ReadOnly Duplicate, "); break;
+      case 6 : sb.append("Region Duplicate, "); break;
+      case 7 : sb.append("ReadOnly Region Duplicate, "); break;
+      default: break;
+    }
+    final int group2 = (typeId >>> 3) & 0x3;
+    switch (group2) {
+      case 0 : sb.append("Heap, "); break;
+      case 1 : sb.append("Direct, "); break;
+      case 2 : sb.append("Map, "); break;
+      case 3 : sb.append("ByteBuffer, "); break;
+      default: break;
+    }
+    final int group3 = (typeId >>> 5) & 0x1;
+    switch (group3) {
+      case 0 : sb.append("Native, "); break;
+      case 1 : sb.append("NonNative, "); break;
+      default: break;
+    }
+    final int group4 = (typeId >>> 6) & 0x1;
+    switch (group4) {
+      case 0 : sb.append("Memory"); break;
+      case 1 : sb.append("Buffer"); break;
+      default: break;
+    }
+    return sb.toString();
   }
 
-  /**
-   * Gets the current number of active direct memory map allocations.
-   * @return the current number of active direct memory map allocations.
-   */
-  public static final long getCurrentDirectMemoryMapAllocations() {
-    return BaseStateImpl.currentDirectMemoryMapAllocations_.get();
+  @Override
+  public final long xxHash64(final long offsetBytes, final long lengthBytes, final long seed) {
+    checkValid();
+    return XxHash64.hash(getUnsafeObject(), getCumulativeOffset(0) + offsetBytes, lengthBytes, seed);
   }
 
-  /**
-   * Gets the current size of active direct memory map allocated.
-   * @return the current size of active direct memory map allocated.
-   */
-  public static final long getCurrentDirectMemoryMapAllocated() {
-    return BaseStateImpl.currentDirectMemoryMapAllocated_.get();
+  @Override
+  public final long xxHash64(final long in, final long seed) {
+    return XxHash64.hash(in, seed);
   }
 
-  //REACHABILITY FENCE
-  static void reachabilityFence(final Object obj) { }
+//@Override
+//public final long getCumulativeOffset(final long offsetBytes) {
+//  assertValid();
+//  return cumBaseOffset_ + offsetBytes;
+//}
+
+//@Override
+//public final long getRegionOffset() {
+//  final Object unsafeObj = getUnsafeObject();
+//  final long nativeBaseOff = getNativeBaseOffset();
+//  return unsafeObj == null
+//      ? cumBaseOffset_ - nativeBaseOff
+//      : cumBaseOffset_ - UnsafeUtil.getArrayBaseOffset(unsafeObj.getClass());
+//}
+
+//@Override
+//public final long getRegionOffset(final long offsetBytes) {
+//  return getRegionOffset() + offsetBytes;
+//}
 
 }
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
index e1dbe93..d52371a 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
@@ -61,11 +61,8 @@ import org.apache.datasketches.memory.WritableMemory;
 @SuppressWarnings("restriction")
 public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements WritableBuffer {
 
-  //Pass-through ctor
-  BaseWritableBufferImpl(final Object unsafeObj, final long nativeBaseOffset,
-      final long regionOffset, final long capacityBytes) {
-    super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes);
-  }
+  //Pass-through constructor
+  BaseWritableBufferImpl(final long capacityBytes) { super(capacityBytes); }
 
   /**
    * The static constructor that chooses the correct ByteBuffer leaf node based on the byte order.
@@ -154,8 +151,8 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
     if (isReadOnly() && !localReadOnly) {
       throw new ReadOnlyException("Writable duplicate of a read-only Buffer is not allowed.");
     }
-    final boolean readOnly = isReadOnly() || localReadOnly;
-    final WritableBuffer wbuf = toDuplicate(readOnly, byteOrder);
+    final boolean finalReadOnly = isReadOnly() || localReadOnly;
+    final WritableBuffer wbuf = toDuplicate(finalReadOnly, byteOrder);
     wbuf.setStartPositionEnd(getStart(), getPosition(), getEnd());
     return wbuf;
   }
@@ -179,8 +176,8 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
       throw new ReadOnlyException(
           "Converting a read-only Buffer to a writable Memory is not allowed.");
     }
-    final boolean readOnly = isReadOnly() || localReadOnly;
-    final WritableMemory wmem = toWritableMemory(readOnly, byteOrder);
+    final boolean finalReadOnly = isReadOnly() || localReadOnly;
+    final WritableMemory wmem = toWritableMemory(finalReadOnly, byteOrder);
     return wmem;
   }
 
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
index 1e75d7d..8a44c71 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
@@ -74,11 +74,8 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
     EMPTY_BYTES = new byte[1024];
   }
 
-  //Pass-through ctor
-  BaseWritableMemoryImpl(final Object unsafeObj, final long nativeBaseOffset,
-      final long regionOffset, final long capacityBytes) {
-    super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes);
-  }
+  //Pass-through constructor
+  BaseWritableMemoryImpl() { }
 
   /**
    * The static constructor that chooses the correct Heap leaf node based on the byte order.
@@ -92,10 +89,11 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
    */
   public static BaseWritableMemoryImpl wrapHeapArray(final Object arr, final long offsetBytes, final long lengthBytes,
       final boolean localReadOnly, final ByteOrder byteOrder, final MemoryRequestServer memReqSvr) {
-    final int typeId = localReadOnly ? READONLY : 0;
+    final long cumOffsetBytes = UnsafeUtil.getArrayBaseOffset(arr.getClass()) + offsetBytes;
+    final int typeId = (localReadOnly ? READONLY : 0);
     return Util.isNativeByteOrder(byteOrder)
-        ? new HeapWritableMemoryImpl(arr, offsetBytes, lengthBytes, typeId, memReqSvr)
-        : new HeapNonNativeWritableMemoryImpl(arr, offsetBytes, lengthBytes, typeId, memReqSvr);
+        ? new HeapWritableMemoryImpl(arr, offsetBytes, lengthBytes, typeId, cumOffsetBytes)
+        : new HeapNonNativeWritableMemoryImpl(arr, offsetBytes, lengthBytes, typeId, cumOffsetBytes);
   }
 
   /**
@@ -163,30 +161,31 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
 
   //REGIONS
   @Override
-  public Memory region(final long offsetBytes, final long capacityBytes, final ByteOrder byteOrder) {
-    return writableRegionImpl(offsetBytes, capacityBytes, true, byteOrder);
+  public Memory region(final long regionOffsetBytes, final long capacityBytes, final ByteOrder byteOrder) {
+    return writableRegionImpl(regionOffsetBytes, capacityBytes, true, byteOrder);
   }
 
   @Override
-  public WritableMemory writableRegion(final long offsetBytes, final long capacityBytes, final ByteOrder byteOrder) {
-    return writableRegionImpl(offsetBytes, capacityBytes, false, byteOrder);
+  public WritableMemory writableRegion(final long regionOffsetBytes, final long capacityBytes,
+      final ByteOrder byteOrder) {
+    return writableRegionImpl(regionOffsetBytes, capacityBytes, false, byteOrder);
   }
 
-  WritableMemory writableRegionImpl(final long offsetBytes, final long capacityBytes,
+  private WritableMemory writableRegionImpl(final long regionOffsetBytes, final long capacityBytes,
       final boolean localReadOnly, final ByteOrder byteOrder) {
     if (isReadOnly() && !localReadOnly) {
       throw new ReadOnlyException("Writable region of a read-only Memory is not allowed.");
     }
-    negativeCheck(offsetBytes, "offsetBytes must be >= 0");
+    negativeCheck(regionOffsetBytes, "offsetBytes must be >= 0");
     negativeCheck(capacityBytes, "capacityBytes must be >= 0");
     Objects.requireNonNull(byteOrder, "byteOrder must be non-null.");
-    checkValidAndBounds(offsetBytes, capacityBytes);
-    final boolean readOnly = isReadOnly() || localReadOnly;
-    return toWritableRegion(offsetBytes, capacityBytes, readOnly, byteOrder);
+    checkValidAndBounds(regionOffsetBytes, capacityBytes);
+    final boolean finalReadOnly = isReadOnly() || localReadOnly;
+    return toWritableRegion(regionOffsetBytes, capacityBytes, finalReadOnly, byteOrder);
   }
 
   abstract BaseWritableMemoryImpl toWritableRegion(
-      long offsetBytes, long capcityBytes, boolean readOnly, ByteOrder byteOrder);
+      long regionOffsetBytes, long capacityBytes, boolean finalReadOnly, ByteOrder byteOrder);
 
   //AS BUFFER
   @Override
@@ -199,19 +198,19 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
     return asWritableBuffer(false, byteOrder);
   }
 
-  WritableBuffer asWritableBuffer(final boolean localReadOnly, final ByteOrder byteOrder) {
+  private WritableBuffer asWritableBuffer(final boolean localReadOnly, final ByteOrder byteOrder) {
     Objects.requireNonNull(byteOrder, "byteOrder must be non-null");
     if (isReadOnly() && !localReadOnly) {
       throw new ReadOnlyException(
           "Converting a read-only Memory to a writable Buffer is not allowed.");
     }
-    final boolean readOnly = isReadOnly() || localReadOnly;
-    final WritableBuffer wbuf = toWritableBuffer(readOnly, byteOrder);
+    final boolean finalReadOnly = isReadOnly() || localReadOnly;
+    final WritableBuffer wbuf = toWritableBuffer(finalReadOnly, byteOrder);
     wbuf.setStartPositionEnd(0, 0, getCapacity());
     return wbuf;
   }
 
-  abstract BaseWritableBufferImpl toWritableBuffer(boolean readOnly, ByteOrder byteOrder);
+  abstract BaseWritableBufferImpl toWritableBuffer(boolean finalReadOnly, ByteOrder byteOrder);
 
   //PRIMITIVE getX() and getXArray()
   @Override
@@ -258,7 +257,7 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
   public final int getCharsFromUtf8(final long offsetBytes, final int utf8LengthBytes,
       final Appendable dst) throws IOException, Utf8CodingException {
     checkValidAndBounds(offsetBytes, utf8LengthBytes);
-    return Utf8.getCharsFromUtf8(offsetBytes, utf8LengthBytes, dst, getCumulativeOffset(),
+    return Utf8.getCharsFromUtf8(offsetBytes, utf8LengthBytes, dst, getCumulativeOffset(0),
         getUnsafeObject());
   }
 
@@ -371,7 +370,7 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
   @Override
   public final long putCharsToUtf8(final long offsetBytes, final CharSequence src) {
     checkValid();
-    return Utf8.putCharsToUtf8(offsetBytes, src, getCapacity(), getCumulativeOffset(),
+    return Utf8.putCharsToUtf8(offsetBytes, src, getCapacity(), getCumulativeOffset(0),
         getUnsafeObject());
   }
 
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java
index 1a324f7..b3e9492 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java
@@ -31,66 +31,114 @@ import org.apache.datasketches.memory.WritableBuffer;
  * @author Lee Rhodes
  */
 final class HeapNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl {
-  private static final int id = BUFFER | NONNATIVE | HEAP;
   private final Object unsafeObj;
-  private final MemoryRequestServer memReqSvr;
-  private final byte typeId;
+  private final long offsetBytes;
+  private final long capacityBytes;
+  private final int typeId;
+  private long cumOffsetBytes;
+  private long regionOffsetBytes;
 
   HeapNonNativeWritableBufferImpl(
       final Object unsafeObj,
-      final long regionOffset,
+      final long offsetBytes,
       final long capacityBytes,
       final int typeId,
-      final MemoryRequestServer memReqSvr) {
-    super(unsafeObj, 0L, regionOffset, capacityBytes);
+      final long cumOffsetBytes) {
+    super(capacityBytes);
     this.unsafeObj = unsafeObj;
-    this.memReqSvr = memReqSvr;
-    this.typeId = (byte) (id | (typeId & 0x7));
+    this.offsetBytes = offsetBytes;
+    this.capacityBytes = capacityBytes;
+    this.typeId = removeNnBuf(typeId) | HEAP | BUFFER | NONNATIVE;
+    this.cumOffsetBytes = cumOffsetBytes;
+    this.regionOffsetBytes = 0;
   }
 
   @Override
-  BaseWritableBufferImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
-      final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | REGION;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new HeapWritableBufferImpl(
-            unsafeObj, getRegionOffset(offsetBytes), capacityBytes, type, memReqSvr)
-        : new HeapNonNativeWritableBufferImpl(
-            unsafeObj, getRegionOffset(offsetBytes), capacityBytes, type, memReqSvr);
+  BaseWritableBufferImpl toWritableRegion(
+      final long regionOffsetBytes,
+      final long capacityBytes,
+      final boolean readOnly,
+      final ByteOrder byteOrder) {
+    final Object unsafeObj = this.unsafeObj;
+    final long newOffsetBytes = this.offsetBytes + this.regionOffsetBytes;
+    this.cumOffsetBytes += this.regionOffsetBytes;
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | REGION | (readOnly ? READONLY : 0);
+    if (Util.isNativeByteOrder(byteOrder)) {
+      typeIdOut |= NATIVE;
+      return new HeapWritableBufferImpl(unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new HeapNonNativeWritableBufferImpl(unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+    }
   }
 
   @Override
   BaseWritableBufferImpl toDuplicate(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | DUPLICATE;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new HeapWritableBufferImpl(
-            unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr)
-        : new HeapNonNativeWritableBufferImpl(
-            unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr);
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | DUPLICATE | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new HeapWritableBufferImpl(
+          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new HeapNonNativeWritableBufferImpl(
+          unsafeObj, regionOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+    }
   }
 
   @Override
   BaseWritableMemoryImpl toWritableMemory(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly);
-    return Util.isNativeByteOrder(byteOrder)
-        ? new HeapWritableMemoryImpl(
-            unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr)
-        : new HeapNonNativeWritableMemoryImpl(
-            unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr);
+    int typeIdOut = removeNnBuf(typeId) | MEMORY | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new HeapWritableMemoryImpl(
+          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new HeapNonNativeWritableMemoryImpl(
+          unsafeObj, regionOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+    }
+  }
+
+  @Override
+  public long getCapacity() {
+    assertValid();
+    return capacityBytes;
+  }
+
+  @Override
+  public long getCumulativeOffset() {
+    assertValid();
+    return cumOffsetBytes;
   }
 
   @Override
   public MemoryRequestServer getMemoryRequestServer() {
-    return memReqSvr;
+    return null;
+  }
+
+  @Override
+  public long getNativeBaseOffset() {
+    return 0;
+  }
+
+  @Override
+  public long getRegionOffset() {
+    assertValid();
+    return regionOffsetBytes;
   }
 
   @Override
   int getTypeId() {
-    return typeId & 0xff;
+    assertValid();
+    return typeId;
   }
 
   @Override
   Object getUnsafeObject() {
+    assertValid();
     return unsafeObj;
   }
 
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java
index 91702c5..7ca8627 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java
@@ -31,56 +31,99 @@ import org.apache.datasketches.memory.WritableMemory;
  * @author Lee Rhodes
  */
 final class HeapNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl {
-  private static final int id = MEMORY | NONNATIVE | HEAP;
   private final Object unsafeObj;
-  private final MemoryRequestServer memReqSvr;
-  private final byte typeId;
+  private final long offsetBytes;
+  private final long capacityBytes;
+  private final int typeId;
+  private long cumOffsetBytes;
+  private long regionOffsetBytes;
 
   HeapNonNativeWritableMemoryImpl(
       final Object unsafeObj,
-      final long regionOffset,
+      final long offsetBytes,
       final long capacityBytes,
       final int typeId,
-      final MemoryRequestServer memReqSvr) {
-    super(unsafeObj, 0L, regionOffset, capacityBytes);
+      final long cumOffsetBytes) {
+    super();
     this.unsafeObj = unsafeObj;
-    this.memReqSvr = memReqSvr;
-    this.typeId = (byte) (id | (typeId & 0x7));
+    this.offsetBytes = offsetBytes;
+    this.capacityBytes = capacityBytes;
+    this.typeId = removeNnBuf(typeId) | HEAP | MEMORY | NONNATIVE;
+    this.cumOffsetBytes = cumOffsetBytes;
+    this.regionOffsetBytes = 0;
   }
 
   @Override
-  BaseWritableMemoryImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
-      final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | REGION;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new HeapWritableMemoryImpl(
-            unsafeObj, getRegionOffset(offsetBytes), capacityBytes, type, memReqSvr)
-        : new HeapNonNativeWritableMemoryImpl(
-            unsafeObj, getRegionOffset(offsetBytes), capacityBytes, type, memReqSvr);
+  BaseWritableMemoryImpl toWritableRegion(
+      final long regionOffsetBytes,
+      final long capacityBytes,
+      final boolean readOnly,
+      final ByteOrder byteOrder) {
+    final Object unsafeObj = this.unsafeObj;
+    final long newOffsetBytes = this.offsetBytes + this.regionOffsetBytes;
+    this.cumOffsetBytes += this.regionOffsetBytes;
+    int typeIdOut = removeNnBuf(typeId) | MEMORY | REGION | (readOnly ? READONLY : 0);
+    if (Util.isNativeByteOrder(byteOrder)) {
+      typeIdOut |= NATIVE;
+      return new HeapWritableMemoryImpl(unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new HeapNonNativeWritableMemoryImpl(unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+    }
   }
 
   @Override
   BaseWritableBufferImpl toWritableBuffer(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly);
-    return Util.isNativeByteOrder(byteOrder)
-        ? new HeapWritableBufferImpl(
-            unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr)
-        : new HeapNonNativeWritableBufferImpl(
-            unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr);
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new HeapWritableBufferImpl(
+          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new HeapNonNativeWritableBufferImpl(
+          unsafeObj, regionOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+    }
+  }
+
+  @Override
+  public long getCapacity() {
+    assertValid();
+    return capacityBytes;
+  }
+
+  @Override
+  public long getCumulativeOffset() {
+    assertValid();
+    return cumOffsetBytes;
   }
 
   @Override
   public MemoryRequestServer getMemoryRequestServer() {
-    return memReqSvr;
+    return null;
+  }
+
+  @Override
+  public long getNativeBaseOffset() {
+    return 0;
+  }
+
+  @Override
+  public long getRegionOffset() {
+    assertValid();
+    return regionOffsetBytes;
   }
 
   @Override
   int getTypeId() {
-    return typeId & 0xff;
+    assertValid();
+    return typeId;
   }
 
   @Override
   Object getUnsafeObject() {
+    assertValid();
     return unsafeObj;
   }
 
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java
index 033ad87..d57ae2d 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java
@@ -31,66 +31,114 @@ import org.apache.datasketches.memory.WritableBuffer;
  * @author Lee Rhodes
  */
 final class HeapWritableBufferImpl extends NativeWritableBufferImpl {
-  private static final int id = BUFFER | NATIVE | HEAP;
   private final Object unsafeObj;
-  private final MemoryRequestServer memReqSvr;
-  private final byte typeId;
+  private final long offsetBytes;
+  private final long capacityBytes;
+  private final int typeId;
+  private long cumOffsetBytes;
+  private long regionOffsetBytes;
 
   HeapWritableBufferImpl(
       final Object unsafeObj,
-      final long regionOffset,
+      final long offsetBytes,
       final long capacityBytes,
       final int typeId,
-      final MemoryRequestServer memReqSvr) {
-    super(unsafeObj, 0L, regionOffset, capacityBytes);
+      final long cumOffsetBytes) {
+    super(capacityBytes);
     this.unsafeObj = unsafeObj;
-    this.memReqSvr = memReqSvr;
-    this.typeId = (byte) (id | (typeId & 0x7));
+    this.offsetBytes = offsetBytes;
+    this.capacityBytes = capacityBytes;
+    this.typeId = removeNnBuf(typeId) | HEAP | BUFFER | NATIVE;
+    this.cumOffsetBytes = cumOffsetBytes;
+    this.regionOffsetBytes = 0;
   }
 
   @Override
-  BaseWritableBufferImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
-      final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | REGION;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new HeapWritableBufferImpl(
-            unsafeObj, getRegionOffset(offsetBytes), capacityBytes, type, memReqSvr)
-        : new HeapNonNativeWritableBufferImpl(
-            unsafeObj, getRegionOffset(offsetBytes), capacityBytes, type, memReqSvr);
+  BaseWritableBufferImpl toWritableRegion(
+      final long regionOffsetBytes,
+      final long capacityBytes,
+      final boolean readOnly,
+      final ByteOrder byteOrder) {
+    final Object unsafeObj = this.unsafeObj;
+    final long newOffsetBytes = this.offsetBytes + regionOffsetBytes;
+    this.cumOffsetBytes += regionOffsetBytes;
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | REGION | (readOnly ? READONLY : 0);
+    if (Util.isNativeByteOrder(byteOrder)) {
+      typeIdOut |= NATIVE;
+      return new HeapWritableBufferImpl(unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new HeapNonNativeWritableBufferImpl(unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+    }
   }
 
   @Override
   BaseWritableBufferImpl toDuplicate(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | DUPLICATE;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new HeapWritableBufferImpl(
-            unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr)
-        : new HeapNonNativeWritableBufferImpl(
-            unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr);
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | DUPLICATE | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new HeapWritableBufferImpl(
+          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new HeapNonNativeWritableBufferImpl(
+          unsafeObj, regionOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+    }
   }
 
   @Override
   BaseWritableMemoryImpl toWritableMemory(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly);
-    return Util.isNativeByteOrder(byteOrder)
-        ? new HeapWritableMemoryImpl(
-            unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr)
-        : new HeapNonNativeWritableMemoryImpl(
-            unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr);
+    int typeIdOut = removeNnBuf(typeId) | MEMORY | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new HeapWritableMemoryImpl(
+          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new HeapNonNativeWritableMemoryImpl(
+          unsafeObj, regionOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+    }
+  }
+
+  @Override
+  public long getCapacity() {
+    assertValid();
+    return capacityBytes;
+  }
+
+  @Override
+  public long getCumulativeOffset() {
+    assertValid();
+    return cumOffsetBytes;
   }
 
   @Override
   public MemoryRequestServer getMemoryRequestServer() {
-    return memReqSvr;
+    return null;
+  }
+
+  @Override
+  public long getNativeBaseOffset() {
+    return 0;
+  }
+
+  @Override
+  public long getRegionOffset() {
+    assertValid();
+    return regionOffsetBytes;
   }
 
   @Override
   int getTypeId() {
-    return typeId & 0xff;
+    assertValid();
+    return typeId;
   }
 
   @Override
   Object getUnsafeObject() {
+    assertValid();
     return unsafeObj;
   }
 
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java
index d2f05d9..85c75e7 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java
@@ -31,56 +31,99 @@ import org.apache.datasketches.memory.WritableMemory;
  * @author Lee Rhodes
  */
 final class HeapWritableMemoryImpl extends NativeWritableMemoryImpl {
-  private static final int id = MEMORY | NATIVE | HEAP;
   private final Object unsafeObj;
-  private final MemoryRequestServer memReqSvr;
-  private final byte typeId;
+  private final long offsetBytes;
+  private final long capacityBytes;
+  private final int typeId;
+  private long cumOffsetBytes;
+  private long regionOffsetBytes;
 
   HeapWritableMemoryImpl(
       final Object unsafeObj,
-      final long regionOffset,
+      final long offsetBytes,
       final long capacityBytes,
-      final int typeId,
-      final MemoryRequestServer memReqSvr) {
-    super(unsafeObj, 0L, regionOffset, capacityBytes);
+      final int typeId, //if this is RO it stays RO
+      final long cumOffsetBytes) {
+    super();
     this.unsafeObj = unsafeObj;
-    this.memReqSvr = memReqSvr;
-    this.typeId = (byte) (id | (typeId & 0x7));
+    this.offsetBytes = offsetBytes;
+    this.capacityBytes = capacityBytes;
+    this.typeId = removeNnBuf(typeId) | HEAP | MEMORY | NATIVE;
+    this.cumOffsetBytes = cumOffsetBytes;
+    this.regionOffsetBytes = 0;
   }
 
   @Override
-  BaseWritableMemoryImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
-      final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | REGION;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new HeapWritableMemoryImpl(
-            unsafeObj, getRegionOffset(offsetBytes), capacityBytes, type, memReqSvr)
-        : new HeapNonNativeWritableMemoryImpl(
-            unsafeObj, getRegionOffset(offsetBytes), capacityBytes, type, memReqSvr);
+  BaseWritableMemoryImpl toWritableRegion(
+      final long regionOffsetBytes,
+      final long capacityBytes,
+      final boolean readOnly,
+      final ByteOrder byteOrder) {
+    this.regionOffsetBytes = regionOffsetBytes;
+    final long newOffsetBytes = offsetBytes + regionOffsetBytes;
+    cumOffsetBytes += regionOffsetBytes;
+    int typeIdOut = removeNnBuf(typeId) | MEMORY | REGION | (readOnly ? READONLY : 0);
+    if (Util.isNativeByteOrder(byteOrder)) {
+      typeIdOut |= NATIVE;
+      return new HeapWritableMemoryImpl(unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new HeapNonNativeWritableMemoryImpl(unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+    }
   }
 
   @Override
   BaseWritableBufferImpl toWritableBuffer(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly);
-    return Util.isNativeByteOrder(byteOrder)
-        ? new HeapWritableBufferImpl(
-            unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr)
-        : new HeapNonNativeWritableBufferImpl(
-            unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr);
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new HeapWritableBufferImpl(
+          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new HeapNonNativeWritableBufferImpl(
+          unsafeObj, regionOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+    }
+  }
+
+  @Override
+  public long getCapacity() {
+    assertValid();
+    return capacityBytes;
+  }
+
+  @Override
+  public long getCumulativeOffset() {
+    assertValid();
+    return cumOffsetBytes;
   }
 
   @Override
   public MemoryRequestServer getMemoryRequestServer() {
-    return memReqSvr;
+    return null;
+  }
+
+  @Override
+  public long getNativeBaseOffset() {
+    return 0;
+  }
+
+  @Override
+  public long getRegionOffset() {
+    assertValid();
+    return regionOffsetBytes;
   }
 
   @Override
   int getTypeId() {
-    return typeId & 0xff;
+    assertValid();
+    return typeId;
   }
 
   @Override
   Object getUnsafeObject() {
+    assertValid();
     return unsafeObj;
   }
 
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java
index 184c1a6..4dbbc42 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java
@@ -49,14 +49,14 @@ final class MapWritableMemoryImpl extends NativeWritableMemoryImpl {
   }
 
   @Override
-  BaseWritableMemoryImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
+  BaseWritableMemoryImpl toWritableRegion(final long regionOffsetBytes, final long capacityBytes,
       final boolean readOnly, final ByteOrder byteOrder) {
     final int type = setReadOnlyType(typeId, readOnly) | REGION;
     return Util.isNativeByteOrder(byteOrder)
         ? new MapWritableMemoryImpl(
-            nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, valid)
+            nativeBaseOffset, getRegionOffset(regionOffsetBytes), capacityBytes, type, valid)
         : new MapNonNativeWritableMemoryImpl(
-            nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, valid);
+            nativeBaseOffset, getRegionOffset(regionOffsetBytes), capacityBytes, type, valid);
   }
 
   @Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NativeWritableBufferImpl.java
index 2dd1ce2..3b14993 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NativeWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NativeWritableBufferImpl.java
@@ -59,11 +59,8 @@ import org.apache.datasketches.memory.WritableBuffer;
 @SuppressWarnings("restriction")
 abstract class NativeWritableBufferImpl extends BaseWritableBufferImpl {
 
-  //Pass-through ctor
-  NativeWritableBufferImpl(final Object unsafeObj, final long nativeBaseOffset, final long regionOffset,
-      final long capacityBytes) {
-    super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes);
-  }
+  //Pass-through constructor
+  NativeWritableBufferImpl(final long capacityBytes) { super(capacityBytes); }
 
   //PRIMITIVE getX() and getXArray()
   @Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImpl.java
index c16423e..1a7b375 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImpl.java
@@ -59,11 +59,8 @@ import org.apache.datasketches.memory.WritableMemory;
 @SuppressWarnings("restriction")
 abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
 
-  //Pass-through ctor
-  NativeWritableMemoryImpl(final Object unsafeObj, final long nativeBaseOffset,
-      final long regionOffset, final long capacityBytes) {
-    super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes);
-  }
+  //Pass-through constructor
+  NativeWritableMemoryImpl() { }
 
   ///PRIMITIVE getX() and getXArray()
   @Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImpl.java
index a8203ba..8df6111 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImpl.java
@@ -52,11 +52,8 @@ import org.apache.datasketches.memory.WritableBuffer;
 @SuppressWarnings("restriction")
 abstract class NonNativeWritableBufferImpl extends BaseWritableBufferImpl {
 
-  //Pass-through ctor
-  NonNativeWritableBufferImpl(final Object unsafeObj, final long nativeBaseOffset, final long regionOffset,
-      final long capacityBytes) {
-    super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes);
-  }
+  //Pass-through constructor
+  NonNativeWritableBufferImpl(final long capacityBytes) { super(capacityBytes); }
 
   //PRIMITIVE getX() and getXArray()
   @Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImpl.java
index de74333..6d1e460 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImpl.java
@@ -52,11 +52,8 @@ import org.apache.datasketches.memory.WritableMemory;
 @SuppressWarnings("restriction")
 abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
 
-  //Pass-through ctor
-  NonNativeWritableMemoryImpl(final Object unsafeObj, final long nativeBaseOffset,
-      final long regionOffset, final long capacityBytes) {
-    super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes);
-  }
+  //Pass-through constructor
+  NonNativeWritableMemoryImpl() { }
 
   ///PRIMITIVE getX() and getXArray()
   @Override
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
index 4911e7d..1331781 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
@@ -23,7 +23,7 @@
 
 package org.apache.datasketches.memory.internal;
 
-import static org.apache.datasketches.memory.internal.Util.*;
+import static org.apache.datasketches.memory.internal.Util.getResourceFile;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
@@ -56,6 +56,37 @@ public class AllocateDirectMapMemoryTest {
     }
   }
 
+  @Test
+  public void simpleMap2() throws Exception {
+    File file = getResourceFile("GettysburgAddress.txt");
+    try (
+        MapHandle rh =
+        Memory.map(file)
+        )
+    {
+      Memory mem = rh.get();
+      println("Mem Cap: " + mem.getCapacity());
+      println("Cum Offset: " + mem.getCumulativeOffset(0));
+      println("Region Offset: " + mem.getRegionOffset());
+      StringBuilder sb = new StringBuilder();
+      mem.getCharsFromUtf8(43, 176, sb);
+      println(sb.toString());
+
+      Memory mem2 = mem.region(38, 12);
+      println("Mem Cap: " + mem2.getCapacity());
+      println("Cum Offset: " + mem2.getCumulativeOffset(0));
+      println("Region Offset: " + mem2.getRegionOffset());
+      StringBuilder sb2 = new StringBuilder();
+      mem2.getCharsFromUtf8(0, 12, sb2);
+      println(sb2.toString());
+
+
+
+      rh.close();
+    }
+  }
+
+
   @Test
   public void testIllegalArguments() throws Exception {
     File file = getResourceFile("GettysburgAddress.txt");
@@ -163,7 +194,7 @@ public class AllocateDirectMapMemoryTest {
    */
   static void print(final Object o) {
     if (o != null) {
-      //System.out.print(o.toString()); //disable here
+      System.out.print(o.toString()); //disable here
     }
   }
 
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java
index 0461104..b1fccf2 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java
@@ -478,7 +478,6 @@ public class NativeWritableBufferImplTest {
     WritableBuffer buf = reg.asWritableBuffer();
     assertEquals(buf.getRegionOffset(), 32);
     assertEquals(buf.getRegionOffset(0), 32);
-    assertEquals(buf.getCumulativeOffset(), 32 + 16);
     assertEquals(buf.getCumulativeOffset(0), 32 + 16);
   }
 
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java
index 8d52250..e6d13cc 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java
@@ -27,11 +27,11 @@ import static org.testng.Assert.fail;
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 
-import org.apache.datasketches.memory.WritableHandle;
 import org.apache.datasketches.memory.Buffer;
 import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.ReadOnlyException;
 import org.apache.datasketches.memory.WritableBuffer;
+import org.apache.datasketches.memory.WritableHandle;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.annotations.Test;
 
@@ -656,8 +656,8 @@ public class NativeWritableMemoryImplTest {
     WritableMemory reg = wmem.writableRegion(32, 32);
     assertEquals(reg.getRegionOffset(), 32);
     assertEquals(reg.getRegionOffset(0), 32);
-    assertEquals(reg.getCumulativeOffset(), 32 + 16);
     assertEquals(reg.getCumulativeOffset(0), 32 + 16);
+
   }
 
   @Test
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java
index 87f7e35..2b96543 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java
@@ -46,7 +46,8 @@ public class SpecificLeafTest {
     bb.order(ByteOrder.nativeOrder());
 
     Memory mem = Memory.wrap(bb).region(0, bytes, ByteOrder.nativeOrder());
-    assertTrue(((BaseStateImpl)mem).isBBType());
+
+    assertTrue(((BaseStateImpl)mem).isByteBufferType(((BaseStateImpl)mem).getTypeId()));
     assertTrue(mem.isReadOnly());
     checkCrossLeafTypeIds(mem);
     Buffer buf = mem.asBuffer().region(0, bytes, ByteOrder.nativeOrder());
@@ -56,11 +57,11 @@ public class SpecificLeafTest {
     Buffer buf2 = mem2.asBuffer().region(0, bytes, Util.NON_NATIVE_BYTE_ORDER);
     Buffer buf3 = buf2.duplicate();
 
-    assertTrue(((BaseStateImpl)mem).isRegionType());
-    assertTrue(((BaseStateImpl)mem2).isRegionType());
-    assertTrue(((BaseStateImpl)buf).isRegionType());
-    assertTrue(((BaseStateImpl)buf2).isRegionType());
-    assertTrue(((BaseStateImpl)buf3).isDuplicateType());
+    assertTrue(((BaseStateImpl)mem).isRegionType(((BaseStateImpl)mem).getTypeId()));
+    assertTrue(((BaseStateImpl)mem2).isRegionType(((BaseStateImpl)mem2).getTypeId()));
+    assertTrue(((BaseStateImpl)buf).isRegionType(((BaseStateImpl)buf).getTypeId()));
+    assertTrue(((BaseStateImpl)buf2).isRegionType(((BaseStateImpl)buf2).getTypeId()));
+    assertTrue(((BaseStateImpl)buf3).isDuplicateType(((BaseStateImpl)buf3).getTypeId()));
   }
 
   @Test
@@ -68,7 +69,7 @@ public class SpecificLeafTest {
     int bytes = 128;
     try (WritableHandle h = WritableMemory.allocateDirect(bytes)) {
       WritableMemory wmem = h.getWritable(); //native mem
-      assertTrue(((BaseStateImpl)wmem).isDirectType());
+      assertTrue(((BaseStateImpl)wmem).isDirectType(((BaseStateImpl)wmem).getTypeId()));
       assertFalse(wmem.isReadOnly());
       checkCrossLeafTypeIds(wmem);
       WritableMemory nnwmem = wmem.writableRegion(0, bytes, Util.NON_NATIVE_BYTE_ORDER);
@@ -81,11 +82,11 @@ public class SpecificLeafTest {
       Buffer buf2 = mem2.asBuffer().region(0, bytes, Util.NON_NATIVE_BYTE_ORDER);
       Buffer buf3 = buf2.duplicate();
 
-      assertTrue(((BaseStateImpl)mem).isRegionType());
-      assertTrue(((BaseStateImpl)mem2).isRegionType());
-      assertTrue(((BaseStateImpl)buf).isRegionType());
-      assertTrue(((BaseStateImpl)buf2).isRegionType());
-      assertTrue(((BaseStateImpl)buf3).isDuplicateType());
+      assertTrue(((BaseStateImpl)mem).isRegionType(((BaseStateImpl)mem).getTypeId()));
+      assertTrue(((BaseStateImpl)mem2).isRegionType(((BaseStateImpl)mem2).getTypeId()));
+      assertTrue(((BaseStateImpl)buf).isRegionType(((BaseStateImpl)buf).getTypeId()));
+      assertTrue(((BaseStateImpl)buf2).isRegionType(((BaseStateImpl)buf2).getTypeId()));
+      assertTrue(((BaseStateImpl)buf3).isDuplicateType(((BaseStateImpl)buf3).getTypeId()));
     }
   }
 
@@ -108,7 +109,7 @@ public class SpecificLeafTest {
 
     try (WritableMapHandle h = WritableMemory.writableMap(file, 0L, bytes, ByteOrder.nativeOrder())) {
       WritableMemory mem = h.getWritable(); //native mem
-      assertTrue(((BaseStateImpl)mem).isMapType());
+      assertTrue(((BaseStateImpl)mem).isMapType(((BaseStateImpl)mem).getTypeId()));
       assertFalse(mem.isReadOnly());
       checkCrossLeafTypeIds(mem);
       Memory nnreg = mem.region(0, bytes, Util.NON_NATIVE_BYTE_ORDER);
@@ -121,12 +122,12 @@ public class SpecificLeafTest {
       Buffer buf2 = reg2.asBuffer().region(0, bytes, Util.NON_NATIVE_BYTE_ORDER);
       Buffer buf3 = buf2.duplicate();
 
-      assertTrue(((BaseStateImpl)reg).isRegionType());
-      assertTrue(((BaseStateImpl)reg2).isRegionType());
-      assertTrue(((BaseStateImpl)buf).isRegionType());
-      assertTrue(((BaseStateImpl)buf2).isRegionType());
-      assertTrue(((BaseStateImpl)buf3).isDuplicateType());
-      assertTrue(((BaseStateImpl)buf4).isDuplicateType());
+      assertTrue(((BaseStateImpl)reg).isRegionType(((BaseStateImpl)reg).getTypeId()));
+      assertTrue(((BaseStateImpl)reg2).isRegionType(((BaseStateImpl)reg2).getTypeId()));
+      assertTrue(((BaseStateImpl)buf).isRegionType(((BaseStateImpl)buf).getTypeId()));
+      assertTrue(((BaseStateImpl)buf2).isRegionType(((BaseStateImpl)buf2).getTypeId()));
+      assertTrue(((BaseStateImpl)buf3).isDuplicateType(((BaseStateImpl)buf3).getTypeId()));
+      assertTrue(((BaseStateImpl)buf4).isDuplicateType(((BaseStateImpl)buf4).getTypeId()));
     }
   }
 
@@ -134,8 +135,8 @@ public class SpecificLeafTest {
   public void checkHeapLeafs() {
     int bytes = 128;
     Memory mem = Memory.wrap(new byte[bytes]);
-    assertTrue(((BaseStateImpl)mem).isHeapType());
-    assertTrue(((BaseStateImpl)mem).isReadOnlyType());
+    assertTrue(((BaseStateImpl)mem).isHeapType(((BaseStateImpl)mem).getTypeId()));
+    assertTrue(((BaseStateImpl)mem).isReadOnlyType(((BaseStateImpl)mem).getTypeId()));
     checkCrossLeafTypeIds(mem);
     Memory nnreg = mem.region(0, bytes, Util.NON_NATIVE_BYTE_ORDER);
 
@@ -147,47 +148,47 @@ public class SpecificLeafTest {
     Buffer buf2 = reg2.asBuffer().region(0, bytes, Util.NON_NATIVE_BYTE_ORDER);
     Buffer buf3 = buf2.duplicate();
 
-    assertFalse(((BaseStateImpl)mem).isRegionType());
-    assertTrue(((BaseStateImpl)reg2).isRegionType());
-    assertTrue(((BaseStateImpl)buf).isRegionType());
-    assertTrue(((BaseStateImpl)buf2).isRegionType());
-    assertTrue(((BaseStateImpl)buf3).isDuplicateType());
-    assertTrue(((BaseStateImpl)buf4).isDuplicateType());
+    assertFalse(((BaseStateImpl)mem).isRegionType(((BaseStateImpl)mem).getTypeId()));
+    assertTrue(((BaseStateImpl)reg2).isRegionType(((BaseStateImpl)reg2).getTypeId()));
+    assertTrue(((BaseStateImpl)buf).isRegionType(((BaseStateImpl)buf).getTypeId()));
+    assertTrue(((BaseStateImpl)buf2).isRegionType(((BaseStateImpl)buf2).getTypeId()));
+    assertTrue(((BaseStateImpl)buf3).isDuplicateType(((BaseStateImpl)buf3).getTypeId()));
+    assertTrue(((BaseStateImpl)buf4).isDuplicateType(((BaseStateImpl)buf4).getTypeId()));
   }
 
   private static void checkCrossLeafTypeIds(Memory mem) {
     Memory reg1 = mem.region(0, mem.getCapacity());
-    assertTrue(((BaseStateImpl)reg1).isRegionType());
+    assertTrue(((BaseStateImpl)reg1).isRegionType(((BaseStateImpl)reg1).getTypeId()));
 
     Buffer buf1 = reg1.asBuffer();
-    assertTrue(((BaseStateImpl)buf1).isRegionType());
-    assertTrue(((BaseStateImpl)buf1).isBufferType());
+    assertTrue(((BaseStateImpl)buf1).isRegionType(((BaseStateImpl)buf1).getTypeId()));
+    assertTrue(((BaseStateImpl)buf1).isBufferType(((BaseStateImpl)buf1).getTypeId()));
     assertTrue(buf1.isReadOnly());
 
     Buffer buf2 = buf1.duplicate();
-    assertTrue(((BaseStateImpl)buf2).isRegionType());
-    assertTrue(((BaseStateImpl)buf2).isBufferType());
-    assertTrue(((BaseStateImpl)buf2).isDuplicateType());
+    assertTrue(((BaseStateImpl)buf2).isRegionType(((BaseStateImpl)buf2).getTypeId()));
+    assertTrue(((BaseStateImpl)buf2).isBufferType(((BaseStateImpl)buf2).getTypeId()));
+    assertTrue(((BaseStateImpl)buf2).isDuplicateType(((BaseStateImpl)buf2).getTypeId()));
     assertTrue(buf2.isReadOnly());
 
     Memory mem2 = buf1.asMemory(); //
-    assertTrue(((BaseStateImpl)mem2).isRegionType());
-    assertFalse(((BaseStateImpl)mem2).isBufferType());
-    assertFalse(((BaseStateImpl)mem2).isDuplicateType());
+    assertTrue(((BaseStateImpl)mem2).isRegionType(((BaseStateImpl)mem2).getTypeId()));
+    assertFalse(((BaseStateImpl)mem2).isBufferType(((BaseStateImpl)mem2).getTypeId()));
+    assertFalse(((BaseStateImpl)mem2).isDuplicateType(((BaseStateImpl)mem2).getTypeId()));
     assertTrue(mem2.isReadOnly());
 
     Buffer buf3 = buf1.duplicate(Util.NON_NATIVE_BYTE_ORDER);
-    assertTrue(((BaseStateImpl)buf3).isRegionType());
-    assertTrue(((BaseStateImpl)buf3).isBufferType());
-    assertTrue(((BaseStateImpl)buf3).isDuplicateType());
-    assertTrue(((BaseStateImpl)buf3).isNonNativeType());
+    assertTrue(((BaseStateImpl)buf3).isRegionType(((BaseStateImpl)buf3).getTypeId()));
+    assertTrue(((BaseStateImpl)buf3).isBufferType(((BaseStateImpl)buf3).getTypeId()));
+    assertTrue(((BaseStateImpl)buf3).isDuplicateType(((BaseStateImpl)buf3).getTypeId()));
+    assertTrue(((BaseStateImpl)buf3).isNonNativeType(((BaseStateImpl)buf3).getTypeId()));
     assertTrue(buf3.isReadOnly());
 
     Memory mem3 = buf3.asMemory();
-    assertTrue(((BaseStateImpl)mem3).isRegionType());
-    assertFalse(((BaseStateImpl)mem3).isBufferType());
-    assertTrue(((BaseStateImpl)mem3).isDuplicateType());
-    assertTrue(((BaseStateImpl)mem3).isNonNativeType());
+    assertTrue(((BaseStateImpl)mem3).isRegionType(((BaseStateImpl)mem3).getTypeId()));
+    assertFalse(((BaseStateImpl)mem3).isBufferType(((BaseStateImpl)mem3).getTypeId()));
+    assertTrue(((BaseStateImpl)mem3).isDuplicateType(((BaseStateImpl)mem3).getTypeId()));
+    assertTrue(((BaseStateImpl)mem3).isNonNativeType(((BaseStateImpl)mem3).getTypeId()));
     assertTrue(mem3.isReadOnly());
   }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org


[datasketches-memory] 02/03: Interim -- still not working.

Posted by le...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 1d717867acca9b2985cf780535c70234e5f61ea9
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Thu Jan 12 17:59:48 2023 -0800

    Interim -- still not working.
---
 .../memory/internal/AccessByteBuffer.java          |  16 +--
 .../internal/BBNonNativeWritableBufferImpl.java    | 119 +++++++++++++------
 .../internal/BBNonNativeWritableMemoryImpl.java    | 100 +++++++++++-----
 .../memory/internal/BBWritableBufferImpl.java      | 119 +++++++++++++------
 .../memory/internal/BBWritableMemoryImpl.java      | 100 +++++++++++-----
 .../memory/internal/BaseStateImpl.java             |  13 +-
 .../memory/internal/BaseWritableBufferImpl.java    |   7 +-
 .../memory/internal/BaseWritableMemoryImpl.java    |  52 ++++++--
 .../DirectNonNativeWritableBufferImpl.java         | 130 ++++++++++++++------
 .../DirectNonNativeWritableMemoryImpl.java         | 112 +++++++++++++-----
 .../memory/internal/DirectWritableBufferImpl.java  | 131 +++++++++++++++------
 .../memory/internal/DirectWritableMemoryImpl.java  | 112 +++++++++++++-----
 .../internal/HeapNonNativeWritableBufferImpl.java  |  50 +++++---
 .../internal/HeapNonNativeWritableMemoryImpl.java  |  30 +++--
 .../memory/internal/HeapWritableBufferImpl.java    |  48 +++++---
 .../memory/internal/HeapWritableMemoryImpl.java    |  26 ++--
 .../internal/MapNonNativeWritableBufferImpl.java   | 122 ++++++++++++++-----
 .../internal/MapNonNativeWritableMemoryImpl.java   | 103 ++++++++++++----
 .../memory/internal/MapWritableBufferImpl.java     | 122 ++++++++++++++-----
 .../memory/internal/MapWritableMemoryImpl.java     | 103 ++++++++++++----
 .../apache/datasketches/memory/internal/Utf8.java  |   1 -
 .../apache/datasketches/memory/internal/Util.java  |  19 +--
 .../memory/internal/AaByteBufferTest.java          |  53 +++++++++
 .../internal/AllocateDirectMapMemoryTest.java      |  18 +--
 .../memory/internal/BaseStateTest.java             |   4 +-
 .../datasketches/memory/internal/Buffer2Test.java  |   4 +-
 .../memory/internal/SpecificLeafTest.java          |  68 ++++++-----
 27 files changed, 1283 insertions(+), 499 deletions(-)

diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AccessByteBuffer.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AccessByteBuffer.java
index 2ec9020..71f30a7 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AccessByteBuffer.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AccessByteBuffer.java
@@ -48,7 +48,7 @@ final class AccessByteBuffer {
 
   final long nativeBaseOffset;
   final long capacityBytes;
-  final long regionOffset;
+  final long offsetBytes;
   final Object unsafeObj;
   final boolean resourceReadOnly;
   final ByteOrder byteOrder; //not used externally, here for reference.
@@ -65,13 +65,13 @@ final class AccessByteBuffer {
     if (direct) {
       nativeBaseOffset = ((sun.nio.ch.DirectBuffer) byteBuf).address();
       unsafeObj = null;
-      regionOffset = 0L; //address() is already adjusted for direct slices, so regionOffset = 0
+      offsetBytes = 0L; //address() is already adjusted for direct slices, so regionOffset = 0
     } else {
       nativeBaseOffset = 0L;
       // ByteBuffer.arrayOffset() and ByteBuffer.array() throw ReadOnlyBufferException if
       // ByteBuffer is read-only. This uses reflection for both writable and read-only cases.
       // Includes the slice() offset for heap.
-      regionOffset = unsafe.getInt(byteBuf, BYTE_BUFFER_OFFSET_FIELD_OFFSET);
+      offsetBytes = unsafe.getInt(byteBuf, BYTE_BUFFER_OFFSET_FIELD_OFFSET);
       unsafeObj = unsafe.getObject(byteBuf, BYTE_BUFFER_HB_FIELD_OFFSET);
     }
   }
@@ -82,11 +82,11 @@ final class AccessByteBuffer {
    * : wrap(...). See LICENSE.
    */
   static ByteBuffer getDummyReadOnlyDirectByteBuffer(final long address, final int capacity) {
-    final ByteBuffer buf = ZERO_READ_ONLY_DIRECT_BYTE_BUFFER.duplicate();
-    unsafe.putLong(buf, NIO_BUFFER_ADDRESS_FIELD_OFFSET, address);
-    unsafe.putInt(buf, NIO_BUFFER_CAPACITY_FIELD_OFFSET, capacity);
-    buf.limit(capacity);
-    return buf;
+    final ByteBuffer byteBuf = ZERO_READ_ONLY_DIRECT_BYTE_BUFFER.duplicate();
+    unsafe.putLong(byteBuf, NIO_BUFFER_ADDRESS_FIELD_OFFSET, address);
+    unsafe.putInt(byteBuf, NIO_BUFFER_CAPACITY_FIELD_OFFSET, capacity);
+    byteBuf.limit(capacity);
+    return byteBuf;
   }
 
 }
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableBufferImpl.java
index 8fbce11..cc4e834 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableBufferImpl.java
@@ -32,80 +32,127 @@ import org.apache.datasketches.memory.WritableBuffer;
  * @author Lee Rhodes
  */
 final class BBNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl {
-  private static final int id = BUFFER | NONNATIVE | BYTEBUF;
-  private final Object unsafeObj;
-  private final long nativeBaseOffset; //used to compute cumBaseOffset
   private final ByteBuffer byteBuf; //holds a reference to a ByteBuffer until we are done with it.
+  private final Object unsafeObj;
+  private final long nativeBaseOffset;
+  private final long offsetBytes;
+  private final long capacityBytes;
+  private final int typeId;
+  private long cumOffsetBytes;
+  private long regionOffsetBytes;
   private final MemoryRequestServer memReqSvr;
-  private final byte typeId;
 
   BBNonNativeWritableBufferImpl(
       final Object unsafeObj,
       final long nativeBaseOffset,
-      final long regionOffset,
+      final long offsetBytes,
       final long capacityBytes,
       final int typeId,
-      final ByteBuffer byteBuf,
-      final MemoryRequestServer memReqSvr) {
-    super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes);
+      final long cumOffsetBytes,
+      final MemoryRequestServer memReqSvr,
+      final ByteBuffer byteBuf) {
+    super(capacityBytes);
     this.unsafeObj = unsafeObj;
     this.nativeBaseOffset = nativeBaseOffset;
-    this.byteBuf = byteBuf;
+    this.offsetBytes = offsetBytes;
+    this.capacityBytes = capacityBytes;
+    this.typeId = removeNnBuf(typeId) | BYTEBUF | BUFFER | NONNATIVE;
+    this.cumOffsetBytes = cumOffsetBytes;
+    this.regionOffsetBytes = 0;
     this.memReqSvr = memReqSvr;
-    this.typeId = (byte) (id | (typeId & 0x7));
+    this.byteBuf = byteBuf;
+  }
+
+  @Override
+  BaseWritableBufferImpl toWritableRegion(
+      final long regionOffsetBytes,
+      final long capacityBytes,
+      final boolean readOnly,
+      final ByteOrder byteOrder) {
+    this.regionOffsetBytes = regionOffsetBytes;
+    final long newOffsetBytes = offsetBytes + regionOffsetBytes;
+    cumOffsetBytes += regionOffsetBytes;
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | REGION | (readOnly ? READONLY : 0);
+
+    if (Util.isNativeByteOrder(byteOrder)) {
+      typeIdOut |= NATIVE;
+      return new BBWritableBufferImpl(
+          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new BBNonNativeWritableBufferImpl(
+          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+    }
   }
 
   @Override
-  BaseWritableBufferImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
-      final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | REGION;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new BBWritableBufferImpl(
-          unsafeObj, nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, byteBuf, memReqSvr)
-        : new BBNonNativeWritableBufferImpl(
-          unsafeObj, nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, byteBuf, memReqSvr);
+  BaseWritableMemoryImpl toWritableMemory(final boolean readOnly, final ByteOrder byteOrder) {
+    int typeIdOut = removeNnBuf(typeId) | MEMORY | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new BBWritableMemoryImpl(
+          unsafeObj, nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new BBNonNativeWritableMemoryImpl(
+          unsafeObj, nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+    }
   }
 
   @Override
   BaseWritableBufferImpl toDuplicate(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | DUPLICATE;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new BBWritableBufferImpl(
-            unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr)
-        : new BBNonNativeWritableBufferImpl(
-            unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr);
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | DUPLICATE | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new BBWritableBufferImpl(
+          unsafeObj, nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new BBNonNativeWritableBufferImpl(
+          unsafeObj, nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+    }
   }
 
   @Override
-  BaseWritableMemoryImpl toWritableMemory(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly);
-    return Util.isNativeByteOrder(byteOrder)
-        ? new BBWritableMemoryImpl(
-            unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr)
-        : new BBNonNativeWritableMemoryImpl(
-            unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr);
+  public long getCapacity() {
+    assertValid();
+    return capacityBytes;
   }
 
   @Override
-  public ByteBuffer getByteBuffer() {
+  public long getCumulativeOffset() {
     assertValid();
-    return byteBuf;
+    return cumOffsetBytes;
   }
 
   @Override
   public MemoryRequestServer getMemoryRequestServer() {
-    assertValid();
     return memReqSvr;
   }
 
   @Override
-  long getNativeBaseOffset() {
+  public long getNativeBaseOffset() {
     return nativeBaseOffset;
   }
 
+  @Override
+  public long getOffset() {
+    assertValid();
+    return offsetBytes;
+  }
+
+  @Override
+  public long getRegionOffset() {
+    assertValid();
+    return regionOffsetBytes;
+  }
+
   @Override
   int getTypeId() {
-    return typeId & 0xff;
+    assertValid();
+    return typeId;
   }
 
   @Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableMemoryImpl.java
index 60ed085..6ea83f9 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableMemoryImpl.java
@@ -32,70 +32,112 @@ import org.apache.datasketches.memory.WritableMemory;
  * @author Lee Rhodes
  */
 final class BBNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl {
-  private static final int id = MEMORY | NONNATIVE | BYTEBUF;
-  private final Object unsafeObj;
-  private final long nativeBaseOffset; //used to compute cumBaseOffset
   private final ByteBuffer byteBuf; //holds a reference to a ByteBuffer until we are done with it.
+  private final Object unsafeObj;
+  private final long nativeBaseOffset;
+  private final long offsetBytes;
+  private final long capacityBytes;
+  private final int typeId;
+  private long cumOffsetBytes;
+  private long regionOffsetBytes;
   private final MemoryRequestServer memReqSvr;
-  private final byte typeId;
 
   BBNonNativeWritableMemoryImpl(
       final Object unsafeObj,
       final long nativeBaseOffset,
-      final long regionOffset,
+      final long offsetBytes,
       final long capacityBytes,
       final int typeId,
-      final ByteBuffer byteBuf,
-      final MemoryRequestServer memReqSvr) {
-    super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes);
+      final long cumOffsetBytes,
+      final MemoryRequestServer memReqSvr,
+      final ByteBuffer byteBuf) {
+    super();
     this.unsafeObj = unsafeObj;
     this.nativeBaseOffset = nativeBaseOffset;
-    this.byteBuf = byteBuf;
+    this.offsetBytes = offsetBytes;
+    this.capacityBytes = capacityBytes;
+    this.typeId = removeNnBuf(typeId) | BYTEBUF | MEMORY | NONNATIVE;
+    this.cumOffsetBytes = cumOffsetBytes;
+    this.regionOffsetBytes = 0;
     this.memReqSvr = memReqSvr;
-    this.typeId = (byte) (id | (typeId & 0x7));
+    this.byteBuf = byteBuf;
   }
 
   @Override
-  BaseWritableMemoryImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
-      final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | REGION;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new BBWritableMemoryImpl(
-            unsafeObj, nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, getByteBuffer(), memReqSvr)
-        : new BBNonNativeWritableMemoryImpl(
-            unsafeObj, nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, getByteBuffer(), memReqSvr);
+  BaseWritableMemoryImpl toWritableRegion(
+      final long regionOffsetBytes,
+      final long capacityBytes,
+      final boolean readOnly,
+      final ByteOrder byteOrder) {
+    this.regionOffsetBytes = regionOffsetBytes;
+    final long newOffsetBytes = offsetBytes + regionOffsetBytes;
+    cumOffsetBytes += regionOffsetBytes;
+    int typeIdOut = removeNnBuf(typeId) | MEMORY | REGION | (readOnly ? READONLY : 0);
+
+    if (Util.isNativeByteOrder(byteOrder)) {
+      typeIdOut |= NATIVE;
+      return new BBWritableMemoryImpl(
+          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new BBNonNativeWritableMemoryImpl(
+          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+    }
   }
 
   @Override
   BaseWritableBufferImpl toWritableBuffer(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly);
-    return Util.isNativeByteOrder(byteOrder)
-        ? new BBWritableBufferImpl(
-            unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr)
-        : new BBNonNativeWritableBufferImpl(
-            unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr);
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new BBWritableBufferImpl(
+          unsafeObj, nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new BBNonNativeWritableBufferImpl(
+          unsafeObj, nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+    }
   }
 
   @Override
-  public ByteBuffer getByteBuffer() {
+  public long getCapacity() {
     assertValid();
-    return byteBuf;
+    return capacityBytes;
   }
 
   @Override
-  public MemoryRequestServer getMemoryRequestServer() {
+  public long getCumulativeOffset() {
     assertValid();
+    return cumOffsetBytes;
+  }
+
+  @Override
+  public MemoryRequestServer getMemoryRequestServer() {
     return memReqSvr;
   }
 
   @Override
-  long getNativeBaseOffset() {
+  public long getNativeBaseOffset() {
     return nativeBaseOffset;
   }
 
+  @Override
+  public long getOffset() {
+    assertValid();
+    return offsetBytes;
+  }
+
+  @Override
+  public long getRegionOffset() {
+    assertValid();
+    return regionOffsetBytes;
+  }
+
   @Override
   int getTypeId() {
-    return typeId & 0xff;
+    assertValid();
+    return typeId;
   }
 
   @Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableBufferImpl.java
index 0288488..a05eedc 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableBufferImpl.java
@@ -32,80 +32,127 @@ import org.apache.datasketches.memory.WritableBuffer;
  * @author Lee Rhodes
  */
 final class BBWritableBufferImpl extends NativeWritableBufferImpl {
-  private static final int id = BUFFER | NATIVE | BYTEBUF;
-  private final Object unsafeObj;
-  private final long nativeBaseOffset; //used to compute cumBaseOffset
   private final ByteBuffer byteBuf; //holds a reference to a ByteBuffer until we are done with it.
+  private final Object unsafeObj;
+  private final long nativeBaseOffset;
+  private final long offsetBytes;
+  private final long capacityBytes;
+  private final int typeId;
+  private long cumOffsetBytes;
+  private long regionOffsetBytes;
   private final MemoryRequestServer memReqSvr;
-  private final byte typeId;
 
   BBWritableBufferImpl(
       final Object unsafeObj,
       final long nativeBaseOffset,
-      final long regionOffset,
+      final long offsetBytes,
       final long capacityBytes,
       final int typeId,
-      final ByteBuffer byteBuf,
-      final MemoryRequestServer memReqSvr) {
-    super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes);
+      final long cumOffsetBytes,
+      final MemoryRequestServer memReqSvr,
+      final ByteBuffer byteBuf) {
+    super(capacityBytes);
     this.unsafeObj = unsafeObj;
     this.nativeBaseOffset = nativeBaseOffset;
-    this.byteBuf = byteBuf;
+    this.offsetBytes = offsetBytes;
+    this.capacityBytes = capacityBytes;
+    this.typeId = removeNnBuf(typeId) | BYTEBUF | BUFFER | NATIVE;
+    this.cumOffsetBytes = cumOffsetBytes;
+    this.regionOffsetBytes = 0;
     this.memReqSvr = memReqSvr;
-    this.typeId = (byte) (id | (typeId & 0x7));
+    this.byteBuf = byteBuf;
+  }
+
+  @Override
+  BaseWritableBufferImpl toWritableRegion(
+      final long regionOffsetBytes,
+      final long capacityBytes,
+      final boolean readOnly,
+      final ByteOrder byteOrder) {
+    this.regionOffsetBytes = regionOffsetBytes;
+    final long newOffsetBytes = offsetBytes + regionOffsetBytes;
+    cumOffsetBytes += regionOffsetBytes;
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | REGION | (readOnly ? READONLY : 0);
+
+    if (Util.isNativeByteOrder(byteOrder)) {
+      typeIdOut |= NATIVE;
+      return new BBWritableBufferImpl(
+          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new BBNonNativeWritableBufferImpl(
+          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+    }
   }
 
   @Override
-  BaseWritableBufferImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
-      final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | REGION;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new BBWritableBufferImpl(
-            unsafeObj, nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, byteBuf, memReqSvr)
-        : new BBNonNativeWritableBufferImpl(
-            unsafeObj, nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, byteBuf, memReqSvr);
+  BaseWritableMemoryImpl toWritableMemory(final boolean readOnly, final ByteOrder byteOrder) {
+    int typeIdOut = removeNnBuf(typeId) | MEMORY | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new BBWritableMemoryImpl(
+          unsafeObj, nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new BBNonNativeWritableMemoryImpl(
+          unsafeObj, nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+    }
   }
 
   @Override
   BaseWritableBufferImpl toDuplicate(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | DUPLICATE;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new BBWritableBufferImpl(
-            unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr)
-        : new BBNonNativeWritableBufferImpl(
-            unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr);
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | DUPLICATE | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new BBWritableBufferImpl(
+          unsafeObj, nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new BBNonNativeWritableBufferImpl(
+          unsafeObj, nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+    }
   }
 
   @Override
-  BaseWritableMemoryImpl toWritableMemory(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly);
-    return Util.isNativeByteOrder(byteOrder)
-        ? new BBWritableMemoryImpl(
-            unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr)
-        : new BBNonNativeWritableMemoryImpl(
-            unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr);
+  public long getCapacity() {
+    assertValid();
+    return capacityBytes;
   }
 
   @Override
-  public ByteBuffer getByteBuffer() {
+  public long getCumulativeOffset() {
     assertValid();
-    return byteBuf;
+    return cumOffsetBytes;
   }
 
   @Override
   public MemoryRequestServer getMemoryRequestServer() {
-    assertValid();
     return memReqSvr;
   }
 
   @Override
-  long getNativeBaseOffset() {
+  public long getNativeBaseOffset() {
     return nativeBaseOffset;
   }
 
+  @Override
+  public long getOffset() {
+    assertValid();
+    return offsetBytes;
+  }
+
+  @Override
+  public long getRegionOffset() {
+    assertValid();
+    return regionOffsetBytes;
+  }
+
   @Override
   int getTypeId() {
-    return typeId & 0xff;
+    assertValid();
+    return typeId;
   }
 
   @Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableMemoryImpl.java
index ad06dc9..9c0cf14 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableMemoryImpl.java
@@ -32,70 +32,112 @@ import org.apache.datasketches.memory.WritableMemory;
  * @author Lee Rhodes
  */
 final class BBWritableMemoryImpl extends NativeWritableMemoryImpl {
-  private static final int id = MEMORY | NATIVE | BYTEBUF;
-  private final Object unsafeObj;
-  private final long nativeBaseOffset; //used to compute cumBaseOffset
   private final ByteBuffer byteBuf; //holds a reference to a ByteBuffer until we are done with it.
+  private final Object unsafeObj;
+  private final long nativeBaseOffset;
+  private final long offsetBytes;
+  private final long capacityBytes;
+  private final int typeId;
+  private long cumOffsetBytes;
+  private long regionOffsetBytes;
   private final MemoryRequestServer memReqSvr;
-  private final byte typeId;
 
   BBWritableMemoryImpl(
       final Object unsafeObj,
       final long nativeBaseOffset,
-      final long regionOffset,
+      final long offsetBytes,
       final long capacityBytes,
       final int typeId,
-      final ByteBuffer byteBuf,
-      final MemoryRequestServer memReqSvr) {
-    super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes);
+      final long cumOffsetBytes,
+      final MemoryRequestServer memReqSvr,
+      final ByteBuffer byteBuf) {
+    super();
     this.unsafeObj = unsafeObj;
     this.nativeBaseOffset = nativeBaseOffset;
-    this.byteBuf = byteBuf;
+    this.offsetBytes = offsetBytes;
+    this.capacityBytes = capacityBytes;
+    this.typeId = removeNnBuf(typeId) | BYTEBUF | MEMORY | NATIVE;
+    this.cumOffsetBytes = cumOffsetBytes;
+    this.regionOffsetBytes = 0;
     this.memReqSvr = memReqSvr;
-    this.typeId = (byte) (id | (typeId & 0x7));
+    this.byteBuf = byteBuf;
   }
 
   @Override
-  BaseWritableMemoryImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
-      final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | REGION;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new BBWritableMemoryImpl(
-            unsafeObj, nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, getByteBuffer(), memReqSvr)
-        : new BBNonNativeWritableMemoryImpl(
-            unsafeObj, nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, getByteBuffer(), memReqSvr);
+  BaseWritableMemoryImpl toWritableRegion(
+      final long regionOffsetBytes,
+      final long capacityBytes,
+      final boolean readOnly,
+      final ByteOrder byteOrder) {
+    this.regionOffsetBytes = regionOffsetBytes;
+    final long newOffsetBytes = offsetBytes + regionOffsetBytes;
+    cumOffsetBytes += regionOffsetBytes;
+    int typeIdOut = removeNnBuf(typeId) | MEMORY | REGION | (readOnly ? READONLY : 0);
+
+    if (Util.isNativeByteOrder(byteOrder)) {
+      typeIdOut |= NATIVE;
+      return new BBWritableMemoryImpl(
+          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new BBNonNativeWritableMemoryImpl(
+          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+    }
   }
 
   @Override
   BaseWritableBufferImpl toWritableBuffer(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly);
-    return Util.isNativeByteOrder(byteOrder)
-        ? new BBWritableBufferImpl(
-            unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr)
-        : new BBNonNativeWritableBufferImpl(
-            unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr);
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new BBWritableBufferImpl(
+          unsafeObj, nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new BBNonNativeWritableBufferImpl(
+          unsafeObj, nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+    }
   }
 
   @Override
-  public ByteBuffer getByteBuffer() {
+  public long getCapacity() {
     assertValid();
-    return byteBuf;
+    return capacityBytes;
   }
 
   @Override
-  public MemoryRequestServer getMemoryRequestServer() {
+  public long getCumulativeOffset() {
     assertValid();
+    return cumOffsetBytes;
+  }
+
+  @Override
+  public MemoryRequestServer getMemoryRequestServer() {
     return memReqSvr;
   }
 
   @Override
-  long getNativeBaseOffset() {
+  public long getNativeBaseOffset() {
     return nativeBaseOffset;
   }
 
+  @Override
+  public long getOffset() {
+    assertValid();
+    return offsetBytes;
+  }
+
+  @Override
+  public long getRegionOffset() {
+    assertValid();
+    return regionOffsetBytes;
+  }
+
   @Override
   int getTypeId() {
-    return typeId & 0xff;
+    assertValid();
+    return typeId;
   }
 
   @Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
index 8c64e58..a63343f 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
@@ -183,6 +183,8 @@ public abstract class BaseStateImpl implements BaseState {
   //Overridden by ByteBuffer, Direct and Map leafs
   abstract long getNativeBaseOffset();
 
+  abstract long getOffset();
+
   @Override
   public final ByteOrder getTypeByteOrder() {
     return isNonNativeType(getTypeId()) ? Util.NON_NATIVE_BYTE_ORDER : ByteOrder.nativeOrder();
@@ -394,6 +396,7 @@ public abstract class BaseStateImpl implements BaseState {
    */
   public static final String typeDecode(final int typeId) {
     final StringBuilder sb = new StringBuilder();
+    sb.append(typeId + ": ");
     final int group1 = typeId & 0x7;
     switch (group1) {
       case 1 : sb.append("ReadOnly, "); break;
@@ -410,7 +413,7 @@ public abstract class BaseStateImpl implements BaseState {
       case 0 : sb.append("Heap, "); break;
       case 1 : sb.append("Direct, "); break;
       case 2 : sb.append("Map, "); break;
-      case 3 : sb.append("ByteBuffer, "); break;
+      case 3 : sb.append("Map Direct, "); break;
       default: break;
     }
     final int group3 = (typeId >>> 5) & 0x1;
@@ -421,10 +424,14 @@ public abstract class BaseStateImpl implements BaseState {
     }
     final int group4 = (typeId >>> 6) & 0x1;
     switch (group4) {
-      case 0 : sb.append("Memory"); break;
-      case 1 : sb.append("Buffer"); break;
+      case 0 : sb.append("Memory, "); break;
+      case 1 : sb.append("Buffer, "); break;
       default: break;
     }
+    final int group5 = (typeId >>> 7) & 0x1;
+    switch (group5) {
+      case 1 : sb.append("ByteBuffer"); break;
+    }
     return sb.toString();
   }
 
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
index d52371a..abbb9ac 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
@@ -77,11 +77,12 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
       final MemoryRequestServer memReqSvr) {
     final AccessByteBuffer abb = new AccessByteBuffer(byteBuf);
     final int typeId = (abb.resourceReadOnly || localReadOnly) ? READONLY : 0;
+    final long cumOffsetBytes = 0;
     final BaseWritableBufferImpl bwbi = Util.isNativeByteOrder(byteOrder)
         ? new BBWritableBufferImpl(abb.unsafeObj, abb.nativeBaseOffset,
-            abb.regionOffset, abb.capacityBytes, typeId, byteBuf, memReqSvr)
+            abb.offsetBytes, abb.capacityBytes, typeId, cumOffsetBytes, memReqSvr, byteBuf)
         : new BBNonNativeWritableBufferImpl(abb.unsafeObj, abb.nativeBaseOffset,
-            abb.regionOffset, abb.capacityBytes,  typeId, byteBuf, memReqSvr);
+            abb.offsetBytes, abb.capacityBytes,  typeId, cumOffsetBytes, memReqSvr, byteBuf);
     bwbi.setStartPositionEnd(0, byteBuf.position(), byteBuf.limit());
     return bwbi;
   }
@@ -294,7 +295,7 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
   }
 
   /*
-   * Develper notes: There is no copyTo for Buffers because of the ambiguity of what to do with
+   * Developer notes: There is no copyTo for Buffers because of the ambiguity of what to do with
    * the positional values. Switch to MemoryImpl view to do copyTo.
    */
 
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
index 8a44c71..24226e6 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
@@ -92,8 +92,8 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
     final long cumOffsetBytes = UnsafeUtil.getArrayBaseOffset(arr.getClass()) + offsetBytes;
     final int typeId = (localReadOnly ? READONLY : 0);
     return Util.isNativeByteOrder(byteOrder)
-        ? new HeapWritableMemoryImpl(arr, offsetBytes, lengthBytes, typeId, cumOffsetBytes)
-        : new HeapNonNativeWritableMemoryImpl(arr, offsetBytes, lengthBytes, typeId, cumOffsetBytes);
+        ? new HeapWritableMemoryImpl(arr, offsetBytes, lengthBytes, typeId, cumOffsetBytes, memReqSvr)
+        : new HeapNonNativeWritableMemoryImpl(arr, offsetBytes, lengthBytes, typeId, cumOffsetBytes, memReqSvr);
   }
 
   /**
@@ -109,11 +109,14 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
       final MemoryRequestServer memReqSvr) {
     final AccessByteBuffer abb = new AccessByteBuffer(byteBuf);
     final int typeId = (abb.resourceReadOnly || localReadOnly) ? READONLY : 0;
+    final long cumOffsetBytes = abb.offsetBytes + (abb.unsafeObj == null
+        ? abb.nativeBaseOffset
+        : UnsafeUtil.getArrayBaseOffset(abb.unsafeObj.getClass()));
     return Util.isNativeByteOrder(byteOrder)
         ? new BBWritableMemoryImpl(abb.unsafeObj, abb.nativeBaseOffset,
-            abb.regionOffset, abb.capacityBytes, typeId, byteBuf, memReqSvr)
+            abb.offsetBytes, abb.capacityBytes, typeId, cumOffsetBytes, memReqSvr, byteBuf)
         : new BBNonNativeWritableMemoryImpl(abb.unsafeObj, abb.nativeBaseOffset,
-            abb.regionOffset, abb.capacityBytes,  typeId, byteBuf, memReqSvr);
+            abb.offsetBytes, abb.capacityBytes,  typeId, cumOffsetBytes, memReqSvr, byteBuf);
   }
 
   /**
@@ -130,11 +133,22 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
     final AllocateDirectWritableMap dirWMap =
         new AllocateDirectWritableMap(file, fileOffsetBytes, capacityBytes, localReadOnly);
     final int typeId = (dirWMap.resourceReadOnly || localReadOnly) ? READONLY : 0;
+    final long cumOffsetBytes = dirWMap.nativeBaseOffset;
     final BaseWritableMemoryImpl wmem = Util.isNativeByteOrder(byteOrder)
-        ? new MapWritableMemoryImpl(dirWMap.nativeBaseOffset, 0L, capacityBytes,
-            typeId, dirWMap.getValid())
-        : new MapNonNativeWritableMemoryImpl(dirWMap.nativeBaseOffset, 0L, capacityBytes,
-            typeId, dirWMap.getValid());
+        ? new MapWritableMemoryImpl(
+            dirWMap.nativeBaseOffset,
+            0L,
+            capacityBytes,
+            typeId,
+            cumOffsetBytes,
+            dirWMap.getValid())
+        : new MapNonNativeWritableMemoryImpl(
+            dirWMap.nativeBaseOffset,
+            0L,
+            capacityBytes,
+            typeId,
+            cumOffsetBytes,
+            dirWMap.getValid());
     return new WritableMapHandleImpl(dirWMap, wmem);
   }
 
@@ -149,11 +163,25 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
       final ByteOrder byteOrder, final MemoryRequestServer memReqSvr) {
     final AllocateDirect direct = new AllocateDirect(capacityBytes);
     final int typeId = 0; //direct is never read-only on construction
+    final long nativeBaseOffset = direct.getNativeBaseOffset();
+    final long cumOffsetBytes = nativeBaseOffset;
     final BaseWritableMemoryImpl wmem = Util.isNativeByteOrder(byteOrder)
-        ? new DirectWritableMemoryImpl(direct.getNativeBaseOffset(), 0L, capacityBytes,
-            typeId, direct.getValid(), memReqSvr)
-        : new DirectNonNativeWritableMemoryImpl(direct.getNativeBaseOffset(), 0L, capacityBytes,
-            typeId, direct.getValid(), memReqSvr);
+        ? new DirectWritableMemoryImpl(
+            nativeBaseOffset,
+            0L,
+            capacityBytes,
+            typeId,
+            cumOffsetBytes,
+            memReqSvr,
+            direct.getValid())
+        : new DirectNonNativeWritableMemoryImpl(
+            nativeBaseOffset,
+            0L,
+            capacityBytes,
+            typeId,
+            cumOffsetBytes,
+            memReqSvr,
+            direct.getValid());
 
     final WritableHandle handle = new WritableDirectHandleImpl(direct, wmem);
     return handle;
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java
index 3b0a183..7b07234 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java
@@ -31,76 +31,134 @@ import org.apache.datasketches.memory.WritableBuffer;
  * @author Lee Rhodes
  */
 final class DirectNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl {
-  private static final int id = BUFFER | NONNATIVE | DIRECT;
-  private final long nativeBaseOffset; //used to compute cumBaseOffset
-  private final StepBoolean valid; //a reference only
+  private final long nativeBaseOffset;
+  private final long offsetBytes;
+  private final long capacityBytes;
+  private final int typeId;
+  private long cumOffsetBytes;
+  private long regionOffsetBytes;
   private final MemoryRequestServer memReqSvr;
-  private final byte typeId;
+  private final StepBoolean valid; //a reference only
 
   DirectNonNativeWritableBufferImpl(
       final long nativeBaseOffset,
-      final long regionOffset,
+      final long offsetBytes,
       final long capacityBytes,
       final int typeId,
-      final StepBoolean valid,
-      final MemoryRequestServer memReqSvr) {
-    super(null, nativeBaseOffset, regionOffset, capacityBytes);
+      final long cumOffsetBytes,
+      final MemoryRequestServer memReqSvr,
+      final StepBoolean valid) {
+    super(capacityBytes);
     this.nativeBaseOffset = nativeBaseOffset;
-    this.valid = valid;
+    this.offsetBytes = offsetBytes;
+    this.capacityBytes = capacityBytes;
+    this.typeId = removeNnBuf(typeId) | DIRECT | BUFFER | NONNATIVE; //initially cannot be ReadOnly
+    this.cumOffsetBytes = cumOffsetBytes;
+    this.regionOffsetBytes = 0;
     this.memReqSvr = memReqSvr;
-    this.typeId = (byte) (id | (typeId & 0x7));
+    this.valid = valid;
   }
 
   @Override
-  BaseWritableBufferImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
-      final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | REGION;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new DirectWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, valid, memReqSvr)
-        : new DirectNonNativeWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, valid, memReqSvr);
+  BaseWritableBufferImpl toWritableRegion(
+      final long regionOffsetBytes,
+      final long capacityBytes,
+      final boolean readOnly,
+      final ByteOrder byteOrder) {
+    this.regionOffsetBytes = regionOffsetBytes;
+    final long newOffsetBytes = offsetBytes + regionOffsetBytes;
+    cumOffsetBytes += regionOffsetBytes;
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | REGION | (readOnly ? READONLY : 0);
+    if (Util.isNativeByteOrder(byteOrder)) {
+      typeIdOut |= NATIVE;
+      return new DirectWritableBufferImpl(
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new DirectNonNativeWritableBufferImpl(
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+    }
+  }
+
+  @Override
+  BaseWritableMemoryImpl toWritableMemory(final boolean readOnly, final ByteOrder byteOrder) {
+    int typeIdOut = removeNnBuf(typeId) | MEMORY | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new DirectWritableMemoryImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new DirectNonNativeWritableMemoryImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+    }
   }
 
   @Override
   BaseWritableBufferImpl toDuplicate(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | DUPLICATE;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new DirectWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr)
-        : new DirectNonNativeWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr);
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | DUPLICATE | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new DirectWritableBufferImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new DirectNonNativeWritableBufferImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+    }
   }
 
   @Override
-  BaseWritableMemoryImpl toWritableMemory(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly);
-    return Util.isNativeByteOrder(byteOrder)
-        ? new DirectWritableMemoryImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr)
-        : new DirectNonNativeWritableMemoryImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr);
+  public boolean isValid() {
+    return valid.get();
   }
 
   @Override
-  public MemoryRequestServer getMemoryRequestServer() {
+  public long getCapacity() {
     assertValid();
+    return capacityBytes;
+  }
+
+  @Override
+  public long getCumulativeOffset() {
+    assertValid();
+    return cumOffsetBytes;
+  }
+
+  @Override
+  public MemoryRequestServer getMemoryRequestServer() {
     return memReqSvr;
   }
 
   @Override
-  long getNativeBaseOffset() {
+  public long getNativeBaseOffset() {
     return nativeBaseOffset;
   }
 
+  @Override
+  public long getOffset() {
+    assertValid();
+    return offsetBytes;
+  }
+
+  @Override
+  public long getRegionOffset() {
+    assertValid();
+    return regionOffsetBytes;
+  }
+
   @Override
   int getTypeId() {
-    return typeId & 0xff;
+    assertValid();
+    return typeId;
   }
 
   @Override
-  public boolean isValid() {
-    return valid.get();
+  Object getUnsafeObject() {
+    assertValid();
+    return null;
   }
 
 }
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableMemoryImpl.java
index 7be7e74..f5bb988 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableMemoryImpl.java
@@ -31,66 +31,120 @@ import org.apache.datasketches.memory.WritableMemory;
  * @author Lee Rhodes
  */
 final class DirectNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl {
-  private static final int id = MEMORY | NONNATIVE | DIRECT;
-  private final long nativeBaseOffset; //used to compute cumBaseOffset
-  private final StepBoolean valid; //a reference only
+  private final long nativeBaseOffset;
+  private final long offsetBytes;
+  private final long capacityBytes;
+  private final int typeId;
+  private long cumOffsetBytes;
+  private long regionOffsetBytes;
   private final MemoryRequestServer memReqSvr;
-  private final byte typeId;
+  private final StepBoolean valid; //a reference only
 
   DirectNonNativeWritableMemoryImpl(
       final long nativeBaseOffset,
-      final long regionOffset,
+      final long offsetBytes,
       final long capacityBytes,
       final int typeId,
-      final StepBoolean valid,
-      final MemoryRequestServer memReqSvr) {
-    super(null, nativeBaseOffset, regionOffset, capacityBytes);
+      final long cumOffsetBytes,
+      final MemoryRequestServer memReqSvr,
+      final StepBoolean valid) {
+    super();
     this.nativeBaseOffset = nativeBaseOffset;
-    this.valid = valid;
+    this.offsetBytes = offsetBytes;
+    this.capacityBytes = capacityBytes;
+    this.typeId = removeNnBuf(typeId) | DIRECT | MEMORY | NONNATIVE; //initially cannot be ReadOnly
+    this.cumOffsetBytes = cumOffsetBytes;
+    this.regionOffsetBytes = 0;
     this.memReqSvr = memReqSvr;
-    this.typeId = (byte) (id | (typeId & 0x7));
+    this.valid = valid;
   }
 
   @Override
-  BaseWritableMemoryImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
-      final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | REGION;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new DirectWritableMemoryImpl(
-            nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, valid, memReqSvr)
-        : new DirectNonNativeWritableMemoryImpl(
-            nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, valid, memReqSvr);
+  BaseWritableMemoryImpl toWritableRegion(
+      final long regionOffsetBytes,
+      final long capacityBytes,
+      final boolean readOnly,
+      final ByteOrder byteOrder) {
+    this.regionOffsetBytes = regionOffsetBytes;
+    final long newOffsetBytes = offsetBytes + regionOffsetBytes;
+    cumOffsetBytes += regionOffsetBytes;
+    int typeIdOut = removeNnBuf(typeId) | MEMORY | REGION | (readOnly ? READONLY : 0);
+
+    if (Util.isNativeByteOrder(byteOrder)) {
+      typeIdOut |= NATIVE;
+      return new DirectWritableMemoryImpl(
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new DirectNonNativeWritableMemoryImpl(
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+    }
   }
 
   @Override
   BaseWritableBufferImpl toWritableBuffer(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly);
-    return Util.isNativeByteOrder(byteOrder)
-        ? new DirectWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr)
-        : new DirectNonNativeWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr);
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new DirectWritableBufferImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new DirectNonNativeWritableBufferImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+    }
   }
 
   @Override
-  public MemoryRequestServer getMemoryRequestServer() {
+  public boolean isValid() {
+    return valid.get();
+  }
+
+  @Override
+  public long getCapacity() {
+    assertValid();
+    return capacityBytes;
+  }
+
+  @Override
+  public long getCumulativeOffset() {
     assertValid();
+    return cumOffsetBytes;
+  }
+
+  @Override
+  public MemoryRequestServer getMemoryRequestServer() {
     return memReqSvr;
   }
 
   @Override
-  long getNativeBaseOffset() {
+  public long getNativeBaseOffset() {
     return nativeBaseOffset;
   }
 
+  @Override
+  public long getOffset() {
+    assertValid();
+    return offsetBytes;
+  }
+
+  @Override
+  public long getRegionOffset() {
+    assertValid();
+    return regionOffsetBytes;
+  }
+
   @Override
   int getTypeId() {
-    return typeId & 0xff;
+    assertValid();
+    return typeId;
   }
 
   @Override
-  public boolean isValid() {
-    return valid.get();
+  Object getUnsafeObject() {
+    assertValid();
+    return null;
   }
 
 }
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java
index 84e7d5e..c8147e5 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java
@@ -31,76 +31,135 @@ import org.apache.datasketches.memory.WritableBuffer;
  * @author Lee Rhodes
  */
 final class DirectWritableBufferImpl extends NativeWritableBufferImpl {
-  private static final int id = BUFFER | NATIVE | DIRECT;
-  private final long nativeBaseOffset; //used to compute cumBaseOffset
-  private final StepBoolean valid; //a reference only
+  private final long nativeBaseOffset;
+  private final long offsetBytes;
+  private final long capacityBytes;
+  private final int typeId;
+  private long cumOffsetBytes;
+  private long regionOffsetBytes;
   private final MemoryRequestServer memReqSvr;
-  private final byte typeId;
+  private final StepBoolean valid; //a reference only
 
   DirectWritableBufferImpl(
       final long nativeBaseOffset,
-      final long regionOffset,
+      final long offsetBytes,
       final long capacityBytes,
       final int typeId,
-      final StepBoolean valid,
-      final MemoryRequestServer memReqSvr) {
-    super(null, nativeBaseOffset, regionOffset, capacityBytes);
+      final long cumOffsetBytes,
+      final MemoryRequestServer memReqSvr,
+      final StepBoolean valid) {
+    super(capacityBytes);
     this.nativeBaseOffset = nativeBaseOffset;
-    this.valid = valid;
+    this.offsetBytes = offsetBytes;
+    this.capacityBytes = capacityBytes;
+    this.typeId = removeNnBuf(typeId) | DIRECT | BUFFER | NATIVE; //initially cannot be ReadOnly
+    this.cumOffsetBytes = cumOffsetBytes;
+    this.regionOffsetBytes = 0;
     this.memReqSvr = memReqSvr;
-    this.typeId = (byte) (id | (typeId & 0x7));
+    this.valid = valid;
+  }
+
+  @Override
+  BaseWritableBufferImpl toWritableRegion(
+      final long regionOffsetBytes,
+      final long capacityBytes,
+      final boolean readOnly,
+      final ByteOrder byteOrder) {
+    this.regionOffsetBytes = regionOffsetBytes;
+    final long newOffsetBytes = offsetBytes + regionOffsetBytes;
+    cumOffsetBytes += regionOffsetBytes;
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | REGION | (readOnly ? READONLY : 0);
+
+    if (Util.isNativeByteOrder(byteOrder)) {
+      typeIdOut |= NATIVE;
+      return new DirectWritableBufferImpl(
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new DirectNonNativeWritableBufferImpl(
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+    }
   }
 
   @Override
-  BaseWritableBufferImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
-      final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | REGION;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new DirectWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, valid, memReqSvr)
-        : new DirectNonNativeWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, valid, memReqSvr);
+  BaseWritableMemoryImpl toWritableMemory(final boolean readOnly, final ByteOrder byteOrder) {
+    int typeIdOut = removeNnBuf(typeId) | MEMORY | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new DirectWritableMemoryImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new DirectNonNativeWritableMemoryImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+    }
   }
 
   @Override
   BaseWritableBufferImpl toDuplicate(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | DUPLICATE;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new DirectWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr)
-        : new DirectNonNativeWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr);
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | DUPLICATE | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new DirectWritableBufferImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new DirectNonNativeWritableBufferImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+    }
   }
 
   @Override
-  BaseWritableMemoryImpl toWritableMemory(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly);
-    return Util.isNativeByteOrder(byteOrder)
-        ? new DirectWritableMemoryImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr)
-        : new DirectNonNativeWritableMemoryImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr);
+  public boolean isValid() {
+    return valid.get();
   }
 
   @Override
-  public MemoryRequestServer getMemoryRequestServer() {
+  public long getCapacity() {
+    assertValid();
+    return capacityBytes;
+  }
+
+  @Override
+  public long getCumulativeOffset() {
     assertValid();
+    return cumOffsetBytes;
+  }
+
+  @Override
+  public MemoryRequestServer getMemoryRequestServer() {
     return memReqSvr;
   }
 
   @Override
-  long getNativeBaseOffset() {
+  public long getNativeBaseOffset() {
     return nativeBaseOffset;
   }
 
+  @Override
+  public long getOffset() {
+    assertValid();
+    return offsetBytes;
+  }
+
+  @Override
+  public long getRegionOffset() {
+    assertValid();
+    return regionOffsetBytes;
+  }
+
   @Override
   int getTypeId() {
-    return typeId & 0xff;
+    assertValid();
+    return typeId;
   }
 
   @Override
-  public boolean isValid() {
-    return valid.get();
+  Object getUnsafeObject() {
+    assertValid();
+    return null;
   }
 
 }
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableMemoryImpl.java
index 68a3461..8ff0961 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableMemoryImpl.java
@@ -31,66 +31,120 @@ import org.apache.datasketches.memory.WritableMemory;
  * @author Lee Rhodes
  */
 final class DirectWritableMemoryImpl extends NativeWritableMemoryImpl {
-  private static final int id = MEMORY | NATIVE | DIRECT;
-  private final long nativeBaseOffset; //used to compute cumBaseOffset
-  private final StepBoolean valid; //a reference only
+  private final long nativeBaseOffset;
+  private final long offsetBytes;
+  private final long capacityBytes;
+  private final int typeId;
+  private long cumOffsetBytes;
+  private long regionOffsetBytes;
   private final MemoryRequestServer memReqSvr;
-  private final byte typeId;
+  private final StepBoolean valid; //a reference only
 
   DirectWritableMemoryImpl(
       final long nativeBaseOffset,
-      final long regionOffset,
+      final long offsetBytes,
       final long capacityBytes,
       final int typeId,
-      final StepBoolean valid,
-      final MemoryRequestServer memReqSvr) {
-    super(null, nativeBaseOffset, regionOffset, capacityBytes);
+      final long cumOffsetBytes,
+      final MemoryRequestServer memReqSvr,
+      final StepBoolean valid) {
+    super();
     this.nativeBaseOffset = nativeBaseOffset;
-    this.valid = valid;
+    this.offsetBytes = offsetBytes;
+    this.capacityBytes = capacityBytes;
+    this.typeId = removeNnBuf(typeId) | DIRECT | MEMORY | NATIVE; //initially cannot be ReadOnly
+    this.cumOffsetBytes = cumOffsetBytes;
+    this.regionOffsetBytes = 0;
     this.memReqSvr = memReqSvr;
-    this.typeId = (byte) (id | (typeId & 0x7));
+    this.valid = valid;
   }
 
   @Override
-  BaseWritableMemoryImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
-      final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | REGION;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new DirectWritableMemoryImpl(
-            nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, valid, memReqSvr)
-        : new DirectNonNativeWritableMemoryImpl(
-            nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, valid, memReqSvr);
+  BaseWritableMemoryImpl toWritableRegion(
+      final long regionOffsetBytes,
+      final long capacityBytes,
+      final boolean readOnly,
+      final ByteOrder byteOrder) {
+    //this.regionOffsetBytes = regionOffsetBytes;
+    final long newOffsetBytes = offsetBytes + regionOffsetBytes;
+    cumOffsetBytes += regionOffsetBytes;
+    int typeIdOut = removeNnBuf(typeId) | MEMORY | REGION | (readOnly ? READONLY : 0);
+
+    if (Util.isNativeByteOrder(byteOrder)) {
+      typeIdOut |= NATIVE;
+      return new DirectWritableMemoryImpl(
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new DirectNonNativeWritableMemoryImpl(
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+    }
   }
 
   @Override
   BaseWritableBufferImpl toWritableBuffer(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly);
-    return Util.isNativeByteOrder(byteOrder)
-        ? new DirectWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr)
-        : new DirectNonNativeWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr);
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new DirectWritableBufferImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new DirectNonNativeWritableBufferImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+    }
   }
 
   @Override
-  public MemoryRequestServer getMemoryRequestServer() {
+  public boolean isValid() {
+    return valid.get();
+  }
+
+  @Override
+  public long getCapacity() {
+    assertValid();
+    return capacityBytes;
+  }
+
+  @Override
+  public long getCumulativeOffset() {
     assertValid();
+    return cumOffsetBytes;
+  }
+
+  @Override
+  public MemoryRequestServer getMemoryRequestServer() {
     return memReqSvr;
   }
 
   @Override
-  long getNativeBaseOffset() {
+  public long getNativeBaseOffset() {
     return nativeBaseOffset;
   }
 
+  @Override
+  public long getOffset() {
+    assertValid();
+    return offsetBytes;
+  }
+
+  @Override
+  public long getRegionOffset() {
+    assertValid();
+    return regionOffsetBytes;
+  }
+
   @Override
   int getTypeId() {
-    return typeId & 0xff;
+    assertValid();
+    return typeId;
   }
 
   @Override
-  public boolean isValid() {
-    return valid.get();
+  Object getUnsafeObject() {
+    assertValid();
+    return null;
   }
 
 }
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java
index b3e9492..91d98fa 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java
@@ -37,13 +37,15 @@ final class HeapNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl
   private final int typeId;
   private long cumOffsetBytes;
   private long regionOffsetBytes;
+  private final MemoryRequestServer memReqSvr;
 
   HeapNonNativeWritableBufferImpl(
       final Object unsafeObj,
       final long offsetBytes,
       final long capacityBytes,
       final int typeId,
-      final long cumOffsetBytes) {
+      final long cumOffsetBytes,
+      final MemoryRequestServer memReqSvr) {
     super(capacityBytes);
     this.unsafeObj = unsafeObj;
     this.offsetBytes = offsetBytes;
@@ -51,6 +53,7 @@ final class HeapNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl
     this.typeId = removeNnBuf(typeId) | HEAP | BUFFER | NONNATIVE;
     this.cumOffsetBytes = cumOffsetBytes;
     this.regionOffsetBytes = 0;
+    this.memReqSvr = memReqSvr;
   }
 
   @Override
@@ -59,46 +62,49 @@ final class HeapNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl
       final long capacityBytes,
       final boolean readOnly,
       final ByteOrder byteOrder) {
-    final Object unsafeObj = this.unsafeObj;
-    final long newOffsetBytes = this.offsetBytes + this.regionOffsetBytes;
-    this.cumOffsetBytes += this.regionOffsetBytes;
+    this.regionOffsetBytes = regionOffsetBytes;
+    final long newOffsetBytes = offsetBytes + regionOffsetBytes;
+    this.cumOffsetBytes += regionOffsetBytes;
     int typeIdOut = removeNnBuf(typeId) | BUFFER | REGION | (readOnly ? READONLY : 0);
+
     if (Util.isNativeByteOrder(byteOrder)) {
       typeIdOut |= NATIVE;
-      return new HeapWritableBufferImpl(unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+      return new HeapWritableBufferImpl(
+          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
     } else {
       typeIdOut |= NONNATIVE;
-      return new HeapNonNativeWritableBufferImpl(unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+      return new HeapNonNativeWritableBufferImpl(
+          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
     }
   }
 
   @Override
-  BaseWritableBufferImpl toDuplicate(final boolean readOnly, final ByteOrder byteOrder) {
-    int typeIdOut = removeNnBuf(typeId) | BUFFER | DUPLICATE | (readOnly ? READONLY : 0);
+  BaseWritableMemoryImpl toWritableMemory(final boolean readOnly, final ByteOrder byteOrder) {
+    int typeIdOut = removeNnBuf(typeId) | MEMORY | (readOnly ? READONLY : 0);
 
     if (byteOrder == ByteOrder.nativeOrder()) {
       typeIdOut |= NATIVE;
-      return new HeapWritableBufferImpl(
-          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+      return new HeapWritableMemoryImpl(
+          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
     } else {
       typeIdOut |= NONNATIVE;
-      return new HeapNonNativeWritableBufferImpl(
-          unsafeObj, regionOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+      return new HeapNonNativeWritableMemoryImpl(
+          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
     }
   }
 
   @Override
-  BaseWritableMemoryImpl toWritableMemory(final boolean readOnly, final ByteOrder byteOrder) {
-    int typeIdOut = removeNnBuf(typeId) | MEMORY | (readOnly ? READONLY : 0);
+  BaseWritableBufferImpl toDuplicate(final boolean readOnly, final ByteOrder byteOrder) {
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | DUPLICATE | (readOnly ? READONLY : 0);
 
     if (byteOrder == ByteOrder.nativeOrder()) {
       typeIdOut |= NATIVE;
-      return new HeapWritableMemoryImpl(
-          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+      return new HeapWritableBufferImpl(
+          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
     } else {
       typeIdOut |= NONNATIVE;
-      return new HeapNonNativeWritableMemoryImpl(
-          unsafeObj, regionOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+      return new HeapNonNativeWritableBufferImpl(
+          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
     }
   }
 
@@ -116,7 +122,7 @@ final class HeapNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl
 
   @Override
   public MemoryRequestServer getMemoryRequestServer() {
-    return null;
+    return memReqSvr;
   }
 
   @Override
@@ -124,6 +130,12 @@ final class HeapNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl
     return 0;
   }
 
+  @Override
+  public long getOffset() {
+    assertValid();
+    return offsetBytes;
+  }
+
   @Override
   public long getRegionOffset() {
     assertValid();
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java
index 7ca8627..5ebe8db 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java
@@ -37,13 +37,15 @@ final class HeapNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl
   private final int typeId;
   private long cumOffsetBytes;
   private long regionOffsetBytes;
+  private final MemoryRequestServer memReqSvr;
 
   HeapNonNativeWritableMemoryImpl(
       final Object unsafeObj,
       final long offsetBytes,
       final long capacityBytes,
       final int typeId,
-      final long cumOffsetBytes) {
+      final long cumOffsetBytes,
+      final MemoryRequestServer memReqSvr) {
     super();
     this.unsafeObj = unsafeObj;
     this.offsetBytes = offsetBytes;
@@ -51,6 +53,7 @@ final class HeapNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl
     this.typeId = removeNnBuf(typeId) | HEAP | MEMORY | NONNATIVE;
     this.cumOffsetBytes = cumOffsetBytes;
     this.regionOffsetBytes = 0;
+    this.memReqSvr = memReqSvr;
   }
 
   @Override
@@ -59,16 +62,19 @@ final class HeapNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl
       final long capacityBytes,
       final boolean readOnly,
       final ByteOrder byteOrder) {
-    final Object unsafeObj = this.unsafeObj;
-    final long newOffsetBytes = this.offsetBytes + this.regionOffsetBytes;
-    this.cumOffsetBytes += this.regionOffsetBytes;
+    this.regionOffsetBytes = regionOffsetBytes;
+    final long newOffsetBytes = offsetBytes + regionOffsetBytes;
+    this.cumOffsetBytes += regionOffsetBytes;
     int typeIdOut = removeNnBuf(typeId) | MEMORY | REGION | (readOnly ? READONLY : 0);
+
     if (Util.isNativeByteOrder(byteOrder)) {
       typeIdOut |= NATIVE;
-      return new HeapWritableMemoryImpl(unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+      return new HeapWritableMemoryImpl(
+          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
     } else {
       typeIdOut |= NONNATIVE;
-      return new HeapNonNativeWritableMemoryImpl(unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+      return new HeapNonNativeWritableMemoryImpl(
+          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
     }
   }
 
@@ -79,11 +85,11 @@ final class HeapNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl
     if (byteOrder == ByteOrder.nativeOrder()) {
       typeIdOut |= NATIVE;
       return new HeapWritableBufferImpl(
-          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
     } else {
       typeIdOut |= NONNATIVE;
       return new HeapNonNativeWritableBufferImpl(
-          unsafeObj, regionOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
     }
   }
 
@@ -101,7 +107,7 @@ final class HeapNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl
 
   @Override
   public MemoryRequestServer getMemoryRequestServer() {
-    return null;
+    return memReqSvr;
   }
 
   @Override
@@ -109,6 +115,12 @@ final class HeapNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl
     return 0;
   }
 
+  @Override
+  public long getOffset() {
+    assertValid();
+    return offsetBytes;
+  }
+
   @Override
   public long getRegionOffset() {
     assertValid();
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java
index d57ae2d..e54a3cf 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java
@@ -37,13 +37,15 @@ final class HeapWritableBufferImpl extends NativeWritableBufferImpl {
   private final int typeId;
   private long cumOffsetBytes;
   private long regionOffsetBytes;
+  private final MemoryRequestServer memReqSvr;
 
   HeapWritableBufferImpl(
       final Object unsafeObj,
       final long offsetBytes,
       final long capacityBytes,
       final int typeId,
-      final long cumOffsetBytes) {
+      final long cumOffsetBytes,
+      final MemoryRequestServer memReqSvr) {
     super(capacityBytes);
     this.unsafeObj = unsafeObj;
     this.offsetBytes = offsetBytes;
@@ -51,6 +53,7 @@ final class HeapWritableBufferImpl extends NativeWritableBufferImpl {
     this.typeId = removeNnBuf(typeId) | HEAP | BUFFER | NATIVE;
     this.cumOffsetBytes = cumOffsetBytes;
     this.regionOffsetBytes = 0;
+    this.memReqSvr = memReqSvr;
   }
 
   @Override
@@ -59,46 +62,49 @@ final class HeapWritableBufferImpl extends NativeWritableBufferImpl {
       final long capacityBytes,
       final boolean readOnly,
       final ByteOrder byteOrder) {
-    final Object unsafeObj = this.unsafeObj;
-    final long newOffsetBytes = this.offsetBytes + regionOffsetBytes;
+    this.regionOffsetBytes = regionOffsetBytes;
+    final long newOffsetBytes = offsetBytes + regionOffsetBytes;
     this.cumOffsetBytes += regionOffsetBytes;
     int typeIdOut = removeNnBuf(typeId) | BUFFER | REGION | (readOnly ? READONLY : 0);
+
     if (Util.isNativeByteOrder(byteOrder)) {
       typeIdOut |= NATIVE;
-      return new HeapWritableBufferImpl(unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+      return new HeapWritableBufferImpl(
+          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
     } else {
       typeIdOut |= NONNATIVE;
-      return new HeapNonNativeWritableBufferImpl(unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+      return new HeapNonNativeWritableBufferImpl(
+          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
     }
   }
 
   @Override
-  BaseWritableBufferImpl toDuplicate(final boolean readOnly, final ByteOrder byteOrder) {
-    int typeIdOut = removeNnBuf(typeId) | BUFFER | DUPLICATE | (readOnly ? READONLY : 0);
+  BaseWritableMemoryImpl toWritableMemory(final boolean readOnly, final ByteOrder byteOrder) {
+    int typeIdOut = removeNnBuf(typeId) | MEMORY | (readOnly ? READONLY : 0);
 
     if (byteOrder == ByteOrder.nativeOrder()) {
       typeIdOut |= NATIVE;
-      return new HeapWritableBufferImpl(
-          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+      return new HeapWritableMemoryImpl(
+          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
     } else {
       typeIdOut |= NONNATIVE;
-      return new HeapNonNativeWritableBufferImpl(
-          unsafeObj, regionOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+      return new HeapNonNativeWritableMemoryImpl(
+          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
     }
   }
 
   @Override
-  BaseWritableMemoryImpl toWritableMemory(final boolean readOnly, final ByteOrder byteOrder) {
-    int typeIdOut = removeNnBuf(typeId) | MEMORY | (readOnly ? READONLY : 0);
+  BaseWritableBufferImpl toDuplicate(final boolean readOnly, final ByteOrder byteOrder) {
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | DUPLICATE | (readOnly ? READONLY : 0);
 
     if (byteOrder == ByteOrder.nativeOrder()) {
       typeIdOut |= NATIVE;
-      return new HeapWritableMemoryImpl(
-          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+      return new HeapWritableBufferImpl(
+          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
     } else {
       typeIdOut |= NONNATIVE;
-      return new HeapNonNativeWritableMemoryImpl(
-          unsafeObj, regionOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+      return new HeapNonNativeWritableBufferImpl(
+          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
     }
   }
 
@@ -116,7 +122,7 @@ final class HeapWritableBufferImpl extends NativeWritableBufferImpl {
 
   @Override
   public MemoryRequestServer getMemoryRequestServer() {
-    return null;
+    return memReqSvr;
   }
 
   @Override
@@ -124,6 +130,12 @@ final class HeapWritableBufferImpl extends NativeWritableBufferImpl {
     return 0;
   }
 
+  @Override
+  public long getOffset() {
+    assertValid();
+    return offsetBytes;
+  }
+
   @Override
   public long getRegionOffset() {
     assertValid();
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java
index 85c75e7..2da356c 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java
@@ -37,13 +37,15 @@ final class HeapWritableMemoryImpl extends NativeWritableMemoryImpl {
   private final int typeId;
   private long cumOffsetBytes;
   private long regionOffsetBytes;
+  private final MemoryRequestServer memReqSvr;
 
   HeapWritableMemoryImpl(
       final Object unsafeObj,
       final long offsetBytes,
       final long capacityBytes,
-      final int typeId, //if this is RO it stays RO
-      final long cumOffsetBytes) {
+      final int typeId,
+      final long cumOffsetBytes,
+      final MemoryRequestServer memReqSvr) {
     super();
     this.unsafeObj = unsafeObj;
     this.offsetBytes = offsetBytes;
@@ -51,6 +53,7 @@ final class HeapWritableMemoryImpl extends NativeWritableMemoryImpl {
     this.typeId = removeNnBuf(typeId) | HEAP | MEMORY | NATIVE;
     this.cumOffsetBytes = cumOffsetBytes;
     this.regionOffsetBytes = 0;
+    this.memReqSvr = memReqSvr;
   }
 
   @Override
@@ -63,12 +66,15 @@ final class HeapWritableMemoryImpl extends NativeWritableMemoryImpl {
     final long newOffsetBytes = offsetBytes + regionOffsetBytes;
     cumOffsetBytes += regionOffsetBytes;
     int typeIdOut = removeNnBuf(typeId) | MEMORY | REGION | (readOnly ? READONLY : 0);
+
     if (Util.isNativeByteOrder(byteOrder)) {
       typeIdOut |= NATIVE;
-      return new HeapWritableMemoryImpl(unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+      return new HeapWritableMemoryImpl(
+          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
     } else {
       typeIdOut |= NONNATIVE;
-      return new HeapNonNativeWritableMemoryImpl(unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+      return new HeapNonNativeWritableMemoryImpl(
+          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
     }
   }
 
@@ -79,11 +85,11 @@ final class HeapWritableMemoryImpl extends NativeWritableMemoryImpl {
     if (byteOrder == ByteOrder.nativeOrder()) {
       typeIdOut |= NATIVE;
       return new HeapWritableBufferImpl(
-          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
     } else {
       typeIdOut |= NONNATIVE;
       return new HeapNonNativeWritableBufferImpl(
-          unsafeObj, regionOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes);
+          unsafeObj, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
     }
   }
 
@@ -101,7 +107,7 @@ final class HeapWritableMemoryImpl extends NativeWritableMemoryImpl {
 
   @Override
   public MemoryRequestServer getMemoryRequestServer() {
-    return null;
+    return memReqSvr;
   }
 
   @Override
@@ -109,6 +115,12 @@ final class HeapWritableMemoryImpl extends NativeWritableMemoryImpl {
     return 0;
   }
 
+  @Override
+  public long getOffset() {
+    assertValid();
+    return offsetBytes;
+  }
+
   @Override
   public long getRegionOffset() {
     assertValid();
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java
index 31a4f1f..b5333a2 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java
@@ -31,52 +31,98 @@ import org.apache.datasketches.memory.WritableBuffer;
  * @author Lee Rhodes
  */
 final class MapNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl {
-  private static final int id = BUFFER | NONNATIVE | MAP;
-  private final long nativeBaseOffset; //used to compute cumBaseOffset
+  private final long nativeBaseOffset;
+  private final long offsetBytes;
+  private final long capacityBytes;
+  private final int typeId;
+  private long cumOffsetBytes;
+  private long regionOffsetBytes;
   private final StepBoolean valid; //a reference only
-  private final byte typeId;
 
   MapNonNativeWritableBufferImpl(
       final long nativeBaseOffset,
-      final long regionOffset,
+      final long offsetBytes,
       final long capacityBytes,
       final int typeId,
+      final long cumOffsetBytes,
       final StepBoolean valid) {
-    super(null, nativeBaseOffset, regionOffset, capacityBytes);
+    super(capacityBytes);
     this.nativeBaseOffset = nativeBaseOffset;
+    this.offsetBytes = offsetBytes;
+    this.capacityBytes = capacityBytes;
+    this.typeId = removeNnBuf(typeId) | MAP | BUFFER | NONNATIVE;
+    this.cumOffsetBytes = cumOffsetBytes;
+    this.regionOffsetBytes = 0;
     this.valid = valid;
-    this.typeId = (byte) (id | (typeId & 0x7));
   }
 
   @Override
-  BaseWritableBufferImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
-      final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | REGION;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new MapWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, valid)
-        : new MapNonNativeWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, valid);
+  BaseWritableBufferImpl toWritableRegion(
+      final long regionOffsetBytes,
+      final long capacityBytes,
+      final boolean readOnly,
+      final ByteOrder byteOrder) {
+    this.regionOffsetBytes = regionOffsetBytes;
+    final long newOffsetBytes = offsetBytes + regionOffsetBytes;
+    cumOffsetBytes += regionOffsetBytes;
+    int typeIdOut = removeNnBuf(typeId) | MAP | REGION | (readOnly ? READONLY : 0);
+
+    if (Util.isNativeByteOrder(byteOrder)) {
+      typeIdOut |= NATIVE;
+      return new MapWritableBufferImpl(
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new MapNonNativeWritableBufferImpl(
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+    }
+  }
+
+  @Override
+  BaseWritableMemoryImpl toWritableMemory(final boolean readOnly, final ByteOrder byteOrder) {
+    int typeIdOut = removeNnBuf(typeId) | MEMORY | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new MapWritableMemoryImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new MapNonNativeWritableMemoryImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+    }
   }
 
   @Override
   BaseWritableBufferImpl toDuplicate(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | DUPLICATE;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new MapWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid)
-        : new MapNonNativeWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid);
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | DUPLICATE | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new MapWritableBufferImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new MapNonNativeWritableBufferImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+    }
   }
 
   @Override
-  BaseWritableMemoryImpl toWritableMemory(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly);
-    return Util.isNativeByteOrder(byteOrder)
-        ? new MapWritableMemoryImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid)
-        : new MapNonNativeWritableMemoryImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid);
+  public boolean isValid() {
+    return valid.get();
+  }
+
+  @Override
+  public long getCapacity() {
+    assertValid();
+    return capacityBytes;
+  }
+
+  @Override
+  public long getCumulativeOffset() {
+    assertValid();
+    return cumOffsetBytes;
   }
 
   @Override
@@ -85,18 +131,32 @@ final class MapNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl {
   }
 
   @Override
-  long getNativeBaseOffset() {
+  public long getNativeBaseOffset() {
     return nativeBaseOffset;
   }
 
+  @Override
+  public long getOffset() {
+    assertValid();
+    return offsetBytes;
+  }
+
+  @Override
+  public long getRegionOffset() {
+    assertValid();
+    return regionOffsetBytes;
+  }
+
   @Override
   int getTypeId() {
-    return typeId & 0xff;
+    assertValid();
+    return typeId;
   }
 
   @Override
-  public boolean isValid() {
-    return valid.get();
+  Object getUnsafeObject() {
+    assertValid();
+    return null;
   }
 
 }
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableMemoryImpl.java
index 5305e5f..ce53e6f 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableMemoryImpl.java
@@ -31,42 +31,83 @@ import org.apache.datasketches.memory.WritableMemory;
  * @author Lee Rhodes
  */
 final class MapNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl {
-  private static final int id = MEMORY | NONNATIVE | MAP;
-  private final long nativeBaseOffset; //used to compute cumBaseOffset
+  private final long nativeBaseOffset;
+  private final long offsetBytes;
+  private final long capacityBytes;
+  private final int typeId;
+  private long cumOffsetBytes;
+  private long regionOffsetBytes;
   private final StepBoolean valid; //a reference only
-  private final byte typeId;
 
   MapNonNativeWritableMemoryImpl(
       final long nativeBaseOffset,
-      final long regionOffset,
+      final long offsetBytes,
       final long capacityBytes,
       final int typeId,
+      final long cumOffsetBytes,
       final StepBoolean valid) {
-    super(null, nativeBaseOffset, regionOffset, capacityBytes);
+    super();
     this.nativeBaseOffset = nativeBaseOffset;
+    this.offsetBytes = offsetBytes;
+    this.capacityBytes = capacityBytes;
+    this.typeId = removeNnBuf(typeId) | MAP | MEMORY | NONNATIVE;
+    this.cumOffsetBytes = cumOffsetBytes;
+    this.regionOffsetBytes = 0;
     this.valid = valid;
-    this.typeId = (byte) (id | (typeId & 0x7));
   }
 
   @Override
-  BaseWritableMemoryImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
-      final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | REGION;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new MapWritableMemoryImpl(
-            nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, valid)
-        : new MapNonNativeWritableMemoryImpl(
-            nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, valid);
+  BaseWritableMemoryImpl toWritableRegion(
+      final long regionOffsetBytes,
+      final long capacityBytes,
+      final boolean readOnly,
+      final ByteOrder byteOrder) {
+    this.regionOffsetBytes = regionOffsetBytes;
+    final long newOffsetBytes = offsetBytes + regionOffsetBytes;
+    cumOffsetBytes += regionOffsetBytes;
+    int typeIdOut = removeNnBuf(typeId) | MAP | REGION | (readOnly ? READONLY : 0);
+
+    if (Util.isNativeByteOrder(byteOrder)) {
+      typeIdOut |= NATIVE;
+      return new MapWritableMemoryImpl(
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new MapNonNativeWritableMemoryImpl(
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+    }
   }
 
   @Override
   BaseWritableBufferImpl toWritableBuffer(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly);
-    return Util.isNativeByteOrder(byteOrder)
-        ? new MapWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid)
-        : new MapNonNativeWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid);
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new MapWritableBufferImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new MapNonNativeWritableBufferImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+    }
+  }
+
+  @Override
+  public boolean isValid() {
+    return valid.get();
+  }
+
+  @Override
+  public long getCapacity() {
+    assertValid();
+    return capacityBytes;
+  }
+
+  @Override
+  public long getCumulativeOffset() {
+    assertValid();
+    return cumOffsetBytes;
   }
 
   @Override
@@ -75,18 +116,32 @@ final class MapNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl {
   }
 
   @Override
-  long getNativeBaseOffset() {
+  public long getNativeBaseOffset() {
     return nativeBaseOffset;
   }
 
+  @Override
+  public long getOffset() {
+    assertValid();
+    return offsetBytes;
+  }
+
+  @Override
+  public long getRegionOffset() {
+    assertValid();
+    return regionOffsetBytes;
+  }
+
   @Override
   int getTypeId() {
-    return typeId & 0xff;
+    assertValid();
+    return typeId;
   }
 
   @Override
-  public boolean isValid() {
-    return valid.get();
+  Object getUnsafeObject() {
+    assertValid();
+    return null;
   }
 
 }
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java
index 9f7c35c..dfc6017 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java
@@ -31,52 +31,98 @@ import org.apache.datasketches.memory.WritableBuffer;
  * @author Lee Rhodes
  */
 final class MapWritableBufferImpl extends NativeWritableBufferImpl {
-  private static final int id = BUFFER | NATIVE | MAP;
-  private final long nativeBaseOffset; //used to compute cumBaseOffset
+  private final long nativeBaseOffset;
+  private final long offsetBytes;
+  private final long capacityBytes;
+  private final int typeId;
+  private long cumOffsetBytes;
+  private long regionOffsetBytes;
   private final StepBoolean valid; //a reference only
-  private final byte typeId;
 
   MapWritableBufferImpl(
       final long nativeBaseOffset,
-      final long regionOffset,
+      final long offsetBytes,
       final long capacityBytes,
       final int typeId,
+      final long cumOffsetBytes,
       final StepBoolean valid) {
-    super(null, nativeBaseOffset, regionOffset, capacityBytes);
+    super(capacityBytes);
     this.nativeBaseOffset = nativeBaseOffset;
+    this.offsetBytes = offsetBytes;
+    this.capacityBytes = capacityBytes;
+    this.typeId = removeNnBuf(typeId) | MAP | BUFFER | NATIVE;
+    this.cumOffsetBytes = cumOffsetBytes;
+    this.regionOffsetBytes = 0;
     this.valid = valid;
-    this.typeId = (byte) (id | (typeId & 0x7));
   }
 
   @Override
-  BaseWritableBufferImpl toWritableRegion(final long offsetBytes, final long capacityBytes,
-      final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | REGION;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new MapWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, valid)
-        : new MapNonNativeWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(offsetBytes), capacityBytes, type, valid);
+  BaseWritableBufferImpl toWritableRegion(
+      final long regionOffsetBytes,
+      final long capacityBytes,
+      final boolean readOnly,
+      final ByteOrder byteOrder) {
+    this.regionOffsetBytes = regionOffsetBytes;
+    final long newOffsetBytes = offsetBytes + regionOffsetBytes;
+    cumOffsetBytes += regionOffsetBytes;
+    int typeIdOut = removeNnBuf(typeId) | MAP | REGION | (readOnly ? READONLY : 0);
+
+    if (Util.isNativeByteOrder(byteOrder)) {
+      typeIdOut |= NATIVE;
+      return new MapWritableBufferImpl(
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new MapNonNativeWritableBufferImpl(
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+    }
+  }
+
+  @Override
+  BaseWritableMemoryImpl toWritableMemory(final boolean readOnly, final ByteOrder byteOrder) {
+    int typeIdOut = removeNnBuf(typeId) | MEMORY | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new MapWritableMemoryImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new MapNonNativeWritableMemoryImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+    }
   }
 
   @Override
   BaseWritableBufferImpl toDuplicate(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | DUPLICATE;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new MapWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid)
-        : new MapNonNativeWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid);
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | DUPLICATE | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new MapWritableBufferImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new MapNonNativeWritableBufferImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+    }
   }
 
   @Override
-  BaseWritableMemoryImpl toWritableMemory(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly);
-    return Util.isNativeByteOrder(byteOrder)
-        ? new MapWritableMemoryImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid)
-        : new MapNonNativeWritableMemoryImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid);
+  public boolean isValid() {
+    return valid.get();
+  }
+
+  @Override
+  public long getCapacity() {
+    assertValid();
+    return capacityBytes;
+  }
+
+  @Override
+  public long getCumulativeOffset() {
+    assertValid();
+    return cumOffsetBytes;
   }
 
   @Override
@@ -85,18 +131,32 @@ final class MapWritableBufferImpl extends NativeWritableBufferImpl {
   }
 
   @Override
-  long getNativeBaseOffset() {
+  public long getNativeBaseOffset() {
     return nativeBaseOffset;
   }
 
+  @Override
+  public long getOffset() {
+    assertValid();
+    return offsetBytes;
+  }
+
+  @Override
+  public long getRegionOffset() {
+    assertValid();
+    return regionOffsetBytes;
+  }
+
   @Override
   int getTypeId() {
-    return typeId & 0xff;
+    assertValid();
+    return typeId;
   }
 
   @Override
-  public boolean isValid() {
-    return valid.get();
+  Object getUnsafeObject() {
+    assertValid();
+    return null;
   }
 
 }
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java
index 4dbbc42..3216a4f 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java
@@ -31,42 +31,83 @@ import org.apache.datasketches.memory.WritableMemory;
  * @author Lee Rhodes
  */
 final class MapWritableMemoryImpl extends NativeWritableMemoryImpl {
-  private static final int id = MEMORY | NATIVE | MAP;
-  private final long nativeBaseOffset; //used to compute cumBaseOffset
+  private final long nativeBaseOffset;
+  private final long offsetBytes;
+  private final long capacityBytes;
+  private final int typeId;
+  private long cumOffsetBytes;
+  private long regionOffsetBytes;
   private final StepBoolean valid; //a reference only
-  private final byte typeId;
 
   MapWritableMemoryImpl(
       final long nativeBaseOffset,
-      final long regionOffset,
+      final long offsetBytes,
       final long capacityBytes,
       final int typeId,
+      final long cumOffsetBytes,
       final StepBoolean valid) {
-    super(null, nativeBaseOffset, regionOffset, capacityBytes);
+    super();
     this.nativeBaseOffset = nativeBaseOffset;
+    this.offsetBytes = offsetBytes;
+    this.capacityBytes = capacityBytes;
+    this.typeId = removeNnBuf(typeId) | MAP | MEMORY | NATIVE;
+    this.cumOffsetBytes = cumOffsetBytes;
+    this.regionOffsetBytes = cumOffsetBytes - nativeBaseOffset;
     this.valid = valid;
-    this.typeId = (byte) (id | (typeId & 0x7));
   }
 
   @Override
-  BaseWritableMemoryImpl toWritableRegion(final long regionOffsetBytes, final long capacityBytes,
-      final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly) | REGION;
-    return Util.isNativeByteOrder(byteOrder)
-        ? new MapWritableMemoryImpl(
-            nativeBaseOffset, getRegionOffset(regionOffsetBytes), capacityBytes, type, valid)
-        : new MapNonNativeWritableMemoryImpl(
-            nativeBaseOffset, getRegionOffset(regionOffsetBytes), capacityBytes, type, valid);
+  BaseWritableMemoryImpl toWritableRegion(
+      final long regionOffsetBytes,
+      final long capacityBytes,
+      final boolean readOnly,
+      final ByteOrder byteOrder) {
+    //this.regionOffsetBytes = regionOffsetBytes;
+    final long newOffsetBytes = offsetBytes + regionOffsetBytes;
+    cumOffsetBytes += regionOffsetBytes;
+    int typeIdOut = removeNnBuf(typeId) | MAP | REGION | (readOnly ? READONLY : 0);
+
+    if (Util.isNativeByteOrder(byteOrder)) {
+      typeIdOut |= NATIVE;
+      return new MapWritableMemoryImpl(
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new MapNonNativeWritableMemoryImpl(
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+    }
   }
 
   @Override
   BaseWritableBufferImpl toWritableBuffer(final boolean readOnly, final ByteOrder byteOrder) {
-    final int type = setReadOnlyType(typeId, readOnly);
-    return Util.isNativeByteOrder(byteOrder)
-        ? new MapWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid)
-        : new MapNonNativeWritableBufferImpl(
-            nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid);
+    int typeIdOut = removeNnBuf(typeId) | BUFFER | (readOnly ? READONLY : 0);
+
+    if (byteOrder == ByteOrder.nativeOrder()) {
+      typeIdOut |= NATIVE;
+      return new MapWritableBufferImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+    } else {
+      typeIdOut |= NONNATIVE;
+      return new MapNonNativeWritableBufferImpl(
+          nativeBaseOffset, offsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+    }
+  }
+
+  @Override
+  public boolean isValid() {
+    return valid.get();
+  }
+
+  @Override
+  public long getCapacity() {
+    assertValid();
+    return capacityBytes;
+  }
+
+  @Override
+  public long getCumulativeOffset() {
+    assertValid();
+    return cumOffsetBytes;
   }
 
   @Override
@@ -75,18 +116,32 @@ final class MapWritableMemoryImpl extends NativeWritableMemoryImpl {
   }
 
   @Override
-  long getNativeBaseOffset() {
+  public long getNativeBaseOffset() {
     return nativeBaseOffset;
   }
 
+  @Override
+  public long getOffset() {
+    assertValid();
+    return offsetBytes;
+  }
+
+  @Override
+  public long getRegionOffset() {
+    assertValid();
+    return regionOffsetBytes;
+  }
+
   @Override
   int getTypeId() {
-    return typeId & 0xff;
+    assertValid();
+    return typeId;
   }
 
   @Override
-  public boolean isValid() {
-    return valid.get();
+  Object getUnsafeObject() {
+    assertValid();
+    return null;
   }
 
 }
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Utf8.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Utf8.java
index d8fb52d..aee5eaf 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Utf8.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Utf8.java
@@ -67,7 +67,6 @@ final class Utf8 {
     //Decode Direct CharBuffers and all other Appendables
 
     final long address = cumBaseOffset + offsetBytes;
-
     // Optimize for 100% ASCII (Hotspot loves small simple top-level loops like this).
     // This simple loop stops when we encounter a byte >= 0x80 (i.e. non-ASCII).
     // Need to keep this loop int-indexed, because it's faster for Hotspot JIT, it doesn't insert
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Util.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Util.java
index 7660dca..182053a 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Util.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Util.java
@@ -36,15 +36,10 @@ import org.apache.datasketches.memory.Memory;
  * @author Lee Rhodes
  */
 public final class Util {
-  public static final String LS = System.getProperty("line.separator");
 
-  //Byte Order related
-  public static final ByteOrder NON_NATIVE_BYTE_ORDER = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN
-      ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
+  private Util() { }
 
-  public static ByteOrder otherByteOrder(final ByteOrder order) {
-    return (order == ByteOrder.nativeOrder()) ? NON_NATIVE_BYTE_ORDER : ByteOrder.nativeOrder();
-  }
+  public static final String LS = System.getProperty("line.separator");
 
   /**
    * Don't use sun.misc.Unsafe#copyMemory to copy blocks of memory larger than this
@@ -58,9 +53,15 @@ public final class Util {
    */
   public static final int UNSAFE_COPY_THRESHOLD_BYTES = 1024 * 1024;
 
-  private Util() { }
+  //Byte Order related
+  public static final ByteOrder NATIVE_BYTE_ORDER = ByteOrder.nativeOrder();
+
+  public static final ByteOrder NON_NATIVE_BYTE_ORDER = NATIVE_BYTE_ORDER == ByteOrder.LITTLE_ENDIAN
+      ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
 
-  //Byte Order Related
+  public static ByteOrder otherByteOrder(final ByteOrder order) {
+    return (order == NATIVE_BYTE_ORDER) ? NON_NATIVE_BYTE_ORDER : NATIVE_BYTE_ORDER;
+  }
 
   /**
    * Returns true if the given byteOrder is the same as the native byte order.
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AaByteBufferTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AaByteBufferTest.java
new file mode 100644
index 0000000..46ee5af
--- /dev/null
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AaByteBufferTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+
+package org.apache.datasketches.memory.internal;
+
+import java.nio.ByteBuffer;
+
+import org.apache.datasketches.memory.Memory;
+import org.testng.annotations.Test;
+
+public class AaByteBufferTest {
+
+  @Test
+  public void checkBB() {
+    byte[] byteArr = new byte[32];
+    int len = byteArr.length;
+    for (byte i = 0; i < len; i++) { byteArr[i] = i; }
+    ByteBuffer bb = ByteBuffer.wrap(byteArr);
+    Memory mem = Memory.wrap(bb);
+    for (int i = 0; i < len; i++) {
+      //System.out.println(mem.getByte(i));
+    }
+  }
+
+  @Test
+  public void checkHeap() {
+    byte[] byteArr = new byte[32];
+    int len = byteArr.length;
+    for (byte i = 0; i < len; i++) { byteArr[i] = i; }
+    Memory mem = Memory.wrap(byteArr);
+    for (int i = 0; i < len; i++) {
+      //System.out.println(mem.getByte(i));
+    }
+  }
+
+}
+
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
index 1331781..455ad3d 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
@@ -59,29 +59,29 @@ public class AllocateDirectMapMemoryTest {
   @Test
   public void simpleMap2() throws Exception {
     File file = getResourceFile("GettysburgAddress.txt");
-    try (
-        MapHandle rh =
-        Memory.map(file)
-        )
+    try (MapHandle rh = Memory.map(file))
     {
       Memory mem = rh.get();
-      println("Mem Cap: " + mem.getCapacity());
+      println("Mem Cap:    " + mem.getCapacity());
+      println("Native Off: " + ((BaseStateImpl)mem).getNativeBaseOffset());
+      println("Offset:     " + ((BaseStateImpl)mem).getOffset());
       println("Cum Offset: " + mem.getCumulativeOffset(0));
       println("Region Offset: " + mem.getRegionOffset());
       StringBuilder sb = new StringBuilder();
       mem.getCharsFromUtf8(43, 176, sb);
       println(sb.toString());
 
-      Memory mem2 = mem.region(38, 12);
+      println("");
+      Memory mem2 = mem.region(43+76, 20);
       println("Mem Cap: " + mem2.getCapacity());
+      println("Native Off: " + ((BaseStateImpl)mem).getNativeBaseOffset());
+      println("Offset:     " + ((BaseStateImpl)mem).getOffset());
       println("Cum Offset: " + mem2.getCumulativeOffset(0));
       println("Region Offset: " + mem2.getRegionOffset());
       StringBuilder sb2 = new StringBuilder();
       mem2.getCharsFromUtf8(0, 12, sb2);
       println(sb2.toString());
 
-
-
       rh.close();
     }
   }
@@ -194,7 +194,7 @@ public class AllocateDirectMapMemoryTest {
    */
   static void print(final Object o) {
     if (o != null) {
-      System.out.print(o.toString()); //disable here
+      //System.out.print(o.toString()); //disable here
     }
   }
 
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseStateTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseStateTest.java
index 430dfa1..b4a193a 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseStateTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseStateTest.java
@@ -105,9 +105,9 @@ public class BaseStateTest {
 
   @Test
   public void checkIsNativeByteOrder() {
-    assertTrue(BaseStateImpl.isNativeByteOrder(ByteOrder.nativeOrder()));
+    assertTrue(Util.isNativeByteOrder(ByteOrder.nativeOrder()));
     try {
-      BaseStateImpl.isNativeByteOrder(null);
+      Util.isNativeByteOrder(null);
       fail();
     } catch (final IllegalArgumentException e) {}
   }
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java
index e625cb4..8aef3db 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java
@@ -50,7 +50,9 @@ public class Buffer2Test {
 
     Buffer buffer = Buffer.wrap(bb.asReadOnlyBuffer().order(ByteOrder.nativeOrder()));
     while (buffer.hasRemaining()) {
-      assertEquals(bb.get(), buffer.getByte());
+      byte a1 = bb.get();
+      byte b1 = buffer.getByte();
+      assertEquals(a1, b1);
     }
 
     assertEquals(true, buffer.hasArray());
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java
index 2b96543..2c67d7f 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java
@@ -46,8 +46,10 @@ public class SpecificLeafTest {
     bb.order(ByteOrder.nativeOrder());
 
     Memory mem = Memory.wrap(bb).region(0, bytes, ByteOrder.nativeOrder());
-
-    assertTrue(((BaseStateImpl)mem).isByteBufferType(((BaseStateImpl)mem).getTypeId()));
+    BaseStateImpl bsi = (BaseStateImpl)mem;
+    int typeId = bsi.getTypeId();
+    assertTrue(bsi.isByteBufferType(typeId));
+    assertTrue(bsi.isNativeType(typeId));
     assertTrue(mem.isReadOnly());
     checkCrossLeafTypeIds(mem);
     Buffer buf = mem.asBuffer().region(0, bytes, ByteOrder.nativeOrder());
@@ -90,6 +92,33 @@ public class SpecificLeafTest {
     }
   }
 
+  @Test
+  public void checkHeapLeafs() {
+    int bytes = 128;
+    Memory mem = Memory.wrap(new byte[bytes]);
+    BaseStateImpl bsi = (BaseStateImpl)mem;
+    int typeId = bsi.getTypeId();
+    assertTrue(bsi.isHeapType(typeId));
+    assertTrue(bsi.isReadOnlyType(typeId));
+    checkCrossLeafTypeIds(mem);
+    Memory nnreg = mem.region(0, bytes, Util.NON_NATIVE_BYTE_ORDER);
+
+    Memory reg = mem.region(0, bytes, ByteOrder.nativeOrder());
+    Buffer buf = reg.asBuffer().region(0, bytes, ByteOrder.nativeOrder());
+    Buffer buf4 = buf.duplicate();
+
+    Memory reg2 = nnreg.region(0, bytes, Util.NON_NATIVE_BYTE_ORDER);
+    Buffer buf2 = reg2.asBuffer().region(0, bytes, Util.NON_NATIVE_BYTE_ORDER);
+    Buffer buf3 = buf2.duplicate();
+
+    assertFalse(((BaseStateImpl)mem).isRegionType(((BaseStateImpl)mem).getTypeId()));
+    assertTrue(((BaseStateImpl)reg2).isRegionType(((BaseStateImpl)reg2).getTypeId()));
+    assertTrue(((BaseStateImpl)buf).isRegionType(((BaseStateImpl)buf).getTypeId()));
+    assertTrue(((BaseStateImpl)buf2).isRegionType(((BaseStateImpl)buf2).getTypeId()));
+    assertTrue(((BaseStateImpl)buf3).isDuplicateType(((BaseStateImpl)buf3).getTypeId()));
+    assertTrue(((BaseStateImpl)buf4).isDuplicateType(((BaseStateImpl)buf4).getTypeId()));
+  }
+
   @Test
   public void checkMapLeafs() throws Exception {
     File file = new File("TestFile2.bin");
@@ -108,7 +137,7 @@ public class SpecificLeafTest {
     final long bytes = 128;
 
     try (WritableMapHandle h = WritableMemory.writableMap(file, 0L, bytes, ByteOrder.nativeOrder())) {
-      WritableMemory mem = h.getWritable(); //native mem
+      WritableMemory mem = h.getWritable();
       assertTrue(((BaseStateImpl)mem).isMapType(((BaseStateImpl)mem).getTypeId()));
       assertFalse(mem.isReadOnly());
       checkCrossLeafTypeIds(mem);
@@ -131,35 +160,18 @@ public class SpecificLeafTest {
     }
   }
 
-  @Test
-  public void checkHeapLeafs() {
-    int bytes = 128;
-    Memory mem = Memory.wrap(new byte[bytes]);
-    assertTrue(((BaseStateImpl)mem).isHeapType(((BaseStateImpl)mem).getTypeId()));
-    assertTrue(((BaseStateImpl)mem).isReadOnlyType(((BaseStateImpl)mem).getTypeId()));
-    checkCrossLeafTypeIds(mem);
-    Memory nnreg = mem.region(0, bytes, Util.NON_NATIVE_BYTE_ORDER);
-
-    Memory reg = mem.region(0, bytes, ByteOrder.nativeOrder());
-    Buffer buf = reg.asBuffer().region(0, bytes, ByteOrder.nativeOrder());
-    Buffer buf4 = buf.duplicate();
-
-    Memory reg2 = nnreg.region(0, bytes, Util.NON_NATIVE_BYTE_ORDER);
-    Buffer buf2 = reg2.asBuffer().region(0, bytes, Util.NON_NATIVE_BYTE_ORDER);
-    Buffer buf3 = buf2.duplicate();
-
-    assertFalse(((BaseStateImpl)mem).isRegionType(((BaseStateImpl)mem).getTypeId()));
-    assertTrue(((BaseStateImpl)reg2).isRegionType(((BaseStateImpl)reg2).getTypeId()));
-    assertTrue(((BaseStateImpl)buf).isRegionType(((BaseStateImpl)buf).getTypeId()));
-    assertTrue(((BaseStateImpl)buf2).isRegionType(((BaseStateImpl)buf2).getTypeId()));
-    assertTrue(((BaseStateImpl)buf3).isDuplicateType(((BaseStateImpl)buf3).getTypeId()));
-    assertTrue(((BaseStateImpl)buf4).isDuplicateType(((BaseStateImpl)buf4).getTypeId()));
-  }
+//  static void theId(Memory mem) {
+//    int typeId = ((BaseStateImpl)mem).getTypeId();
+//    System.out.println(BaseStateImpl.typeDecode(typeId));
+//  }
+//  static void theId(Buffer buf) {
+//    int typeId = ((BaseStateImpl)buf).getTypeId();
+//    System.out.println(BaseStateImpl.typeDecode(typeId));
+//  }
 
   private static void checkCrossLeafTypeIds(Memory mem) {
     Memory reg1 = mem.region(0, mem.getCapacity());
     assertTrue(((BaseStateImpl)reg1).isRegionType(((BaseStateImpl)reg1).getTypeId()));
-
     Buffer buf1 = reg1.asBuffer();
     assertTrue(((BaseStateImpl)buf1).isRegionType(((BaseStateImpl)buf1).getTypeId()));
     assertTrue(((BaseStateImpl)buf1).isBufferType(((BaseStateImpl)buf1).getTypeId()));


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org


[datasketches-memory] 03/03: Interim - passes all tests, almost done.

Posted by le...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d54aceb3823948908d7cc88fe555693181b2e2ac
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Fri Jan 13 13:56:56 2023 -0800

    Interim - passes all tests, almost done.
---
 .../org/apache/datasketches/memory/BaseState.java  | 55 ++++------------------
 .../org/apache/datasketches/memory/Buffer.java     |  2 +-
 .../memory/DefaultMemoryRequestServer.java         |  2 +-
 .../apache/datasketches/memory/MurmurHash3v2.java  |  4 +-
 .../apache/datasketches/memory/WritableMemory.java |  4 +-
 .../memory/internal/AccessByteBuffer.java          | 10 ++--
 .../internal/BBNonNativeWritableBufferImpl.java    | 23 ++++-----
 .../internal/BBNonNativeWritableMemoryImpl.java    | 23 ++++-----
 .../memory/internal/BBWritableBufferImpl.java      | 31 ++++++------
 .../memory/internal/BBWritableMemoryImpl.java      | 28 +++++------
 .../memory/internal/BaseStateImpl.java             | 32 ++++++++++---
 .../memory/internal/BaseWritableBufferImpl.java    | 10 ++--
 .../DirectNonNativeWritableBufferImpl.java         | 17 ++-----
 .../DirectNonNativeWritableMemoryImpl.java         | 17 ++-----
 .../memory/internal/DirectWritableBufferImpl.java  | 17 ++-----
 .../memory/internal/DirectWritableMemoryImpl.java  | 17 ++-----
 .../internal/HeapNonNativeWritableBufferImpl.java  | 17 ++-----
 .../internal/HeapNonNativeWritableMemoryImpl.java  | 17 ++-----
 .../memory/internal/HeapWritableBufferImpl.java    | 17 ++-----
 .../memory/internal/HeapWritableMemoryImpl.java    | 17 ++-----
 .../internal/MapNonNativeWritableBufferImpl.java   | 17 ++-----
 .../internal/MapNonNativeWritableMemoryImpl.java   | 17 ++-----
 .../memory/internal/MapWritableBufferImpl.java     | 17 ++-----
 .../memory/internal/MapWritableMemoryImpl.java     | 16 ++-----
 .../memory/internal/AaByteBufferTest.java          | 53 ---------------------
 .../internal/AllocateDirectMapMemoryTest.java      | 20 ++++----
 .../datasketches/memory/internal/Buffer2Test.java  |  6 +--
 .../datasketches/memory/internal/BufferTest.java   | 19 ++++----
 .../internal/ExampleMemoryRequestServerTest.java   |  2 +-
 .../datasketches/memory/internal/LeafImplTest.java | 16 +++----
 .../datasketches/memory/internal/MemoryTest.java   |  4 +-
 .../internal/NativeWritableBufferImplTest.java     | 13 +++--
 .../internal/NativeWritableMemoryImplTest.java     |  5 +-
 .../internal/NonNativeWritableBufferImplTest.java  |  8 ++--
 .../internal/NonNativeWritableMemoryImplTest.java  |  4 +-
 .../memory/internal/WritableMemoryTest.java        | 14 +++---
 36 files changed, 204 insertions(+), 387 deletions(-)

diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseState.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseState.java
index 2da19c4..aff64aa 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseState.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseState.java
@@ -115,55 +115,20 @@ public interface BaseState {
   long getCapacity();
 
   /**
-   * Gets the cumulative offset in bytes of this object from the backing resource.
-   * This offset may also include other offset components such as the native off-heap
-   * memory address, DirectByteBuffer split offsets, region offsets, and unsafe arrayBaseOffsets.
-   *
-   * @return the cumulative offset in bytes of this object from the backing resource.
+   * Returns the offset of address zero of this object relative to the base address of the
+   * backing resource. This does not include the object header for heap arrays nor the initial
+   * offset of a memory-mapped file.
+   * @return the offset of address zero of this object relative to the base address of the
+   * backing resource.
    */
-  long getCumulativeOffset();
-
-  /**
-   * Gets the cumulative offset in bytes of this object from the backing resource including the given
-   * localOffsetBytes. This offset may also include other offset components such as the native off-heap
-   * memory address, DirectByteBuffer split offsets, region offsets, and object arrayBaseOffsets.
-   *
-   * @param localOffsetBytes offset to be added to the cumulative offset.
-   * @return the cumulative offset in bytes of this object from the backing resource including the
-   * given offsetBytes.
-   */
-  default long getCumulativeOffset(long localOffsetBytes) {
-    return getCumulativeOffset() + localOffsetBytes;
-  }
-
-  /**
-   * Returns the offset of address zero of this object relative to the address zero of the
-   * backing resource but not including the size of any Java object header.
-   * This is only used when moving directly across to Memory, Buffer or Buffer duplicate.
-   * @return the offset of address zero of this object relative to the address zero of the
-   * backing resource but not including the size of any Java object header.
-   */
-  long getRegionOffset();
-
-  /**
-   * Returns the offset of address zero of this object relative to the address zero of the
-   * backing resource plus the given offsetBytes but not including the size of any Java object
-   * header.
-   * @param offsetBytes the given offsetBytes
-   * @return the offset of address zero of this object relative to the address zero of the
-   * backing resource plus the given offsetBytes but not including the size of any Java object
-   * header.
-   */
-  default long getRegionOffset(long offsetBytes) {
-    return getRegionOffset() + offsetBytes;
-  }
+  long getTotalOffset();
 
   /**
-   * Gets the current Type ByteOrder.
-   * This may be different from the ByteOrder of the backing resource and of the Native Byte Order.
-   * @return the current Type ByteOrder.
+   * Gets the current ByteOrder.
+   * This may be different from the ByteOrder of the backing resource and {@link ByteOrder#nativeOrder()}
+   * @return the current ByteOrder.
    */
-  ByteOrder getTypeByteOrder();
+  ByteOrder getByteOrder();
 
   /**
    * Returns true if this object is backed by an on-heap primitive array
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Buffer.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Buffer.java
index fe4a9c8..9c75edb 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Buffer.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Buffer.java
@@ -143,7 +143,7 @@ public interface Buffer extends BaseBuffer {
    * @return Memory
    */
   default Memory asMemory() {
-    return asMemory(getTypeByteOrder());
+    return asMemory(getByteOrder());
   }
 
   /**
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java
index 51c2d2b..f8f828c 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java
@@ -73,7 +73,7 @@ public final class DefaultMemoryRequestServer implements MemoryRequestServer {
    */
   @Override
   public WritableMemory request(final WritableMemory currentWritableMemory, final long capacityBytes) {
-    final WritableMemory wmem = WritableMemory.allocate((int)capacityBytes, currentWritableMemory.getTypeByteOrder());
+    final WritableMemory wmem = WritableMemory.allocate((int)capacityBytes, currentWritableMemory.getByteOrder());
     return wmem;
   }
 
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MurmurHash3v2.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MurmurHash3v2.java
index 67c4830..673490a 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MurmurHash3v2.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MurmurHash3v2.java
@@ -22,6 +22,8 @@ package org.apache.datasketches.memory;
 import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.apache.datasketches.memory.internal.UnsafeUtil.unsafe;
 
+import org.apache.datasketches.memory.internal.BaseStateImpl;
+
 /**
  * <p>The MurmurHash3 is a fast, non-cryptographic, 128-bit hash function that has
  * excellent avalanche and 2-way bit independence properties.</p>
@@ -177,7 +179,7 @@ public final class MurmurHash3v2 {
     if (uObj == null) {
       throw new IllegalArgumentException("The backing resource of input mem is not on-heap.");
     }
-    long cumOff = mem.getCumulativeOffset(offsetBytes);
+    long cumOff = ((BaseStateImpl)mem).getCumulativeOffset(offsetBytes);
 
     long h1 = seed;
     long h2 = seed;
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMemory.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMemory.java
index feacb1b..d8fbd12 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMemory.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMemory.java
@@ -167,7 +167,7 @@ public interface WritableMemory extends Memory {
    * @return a new <i>WritableMemory</i> representing the defined writable region.
    */
   default WritableMemory writableRegion(long regionOffsetBytes, long capacityBytes) {
-    return writableRegion(regionOffsetBytes, capacityBytes, getTypeByteOrder());
+    return writableRegion(regionOffsetBytes, capacityBytes, getByteOrder());
   }
 
   /**
@@ -201,7 +201,7 @@ public interface WritableMemory extends Memory {
    * @return a new <i>WritableBuffer</i> with a view of this WritableMemory
    */
   default WritableBuffer asWritableBuffer() {
-    return asWritableBuffer(getTypeByteOrder());
+    return asWritableBuffer(getByteOrder());
   }
 
   /**
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AccessByteBuffer.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AccessByteBuffer.java
index 71f30a7..9319e82 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AccessByteBuffer.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AccessByteBuffer.java
@@ -47,6 +47,7 @@ final class AccessByteBuffer {
       UnsafeUtil.getFieldOffset(java.nio.ByteBuffer.class, "offset");
 
   final long nativeBaseOffset;
+  final long initialCumOffset;
   final long capacityBytes;
   final long offsetBytes;
   final Object unsafeObj;
@@ -65,14 +66,17 @@ final class AccessByteBuffer {
     if (direct) {
       nativeBaseOffset = ((sun.nio.ch.DirectBuffer) byteBuf).address();
       unsafeObj = null;
-      offsetBytes = 0L; //address() is already adjusted for direct slices, so regionOffset = 0
+      offsetBytes = 0L; //address() is already adjusted for direct slices, so offset = 0
+      initialCumOffset = nativeBaseOffset;
     } else {
       nativeBaseOffset = 0L;
       // ByteBuffer.arrayOffset() and ByteBuffer.array() throw ReadOnlyBufferException if
-      // ByteBuffer is read-only. This uses reflection for both writable and read-only cases.
-      // Includes the slice() offset for heap.
+      // ByteBuffer is read-only, so this uses reflection for both writable and read-only cases.
+      // OffsetBytes includes the slice() offset for heap.  The original array is still there because
+      // this is a view.
       offsetBytes = unsafe.getInt(byteBuf, BYTE_BUFFER_OFFSET_FIELD_OFFSET);
       unsafeObj = unsafe.getObject(byteBuf, BYTE_BUFFER_HB_FIELD_OFFSET);
+      initialCumOffset = UnsafeUtil.getArrayBaseOffset(unsafeObj.getClass()) + offsetBytes;
     }
   }
 
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableBufferImpl.java
index cc4e834..a024f11 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableBufferImpl.java
@@ -39,7 +39,6 @@ final class BBNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl {
   private final long capacityBytes;
   private final int typeId;
   private long cumOffsetBytes;
-  private long regionOffsetBytes;
   private final MemoryRequestServer memReqSvr;
 
   BBNonNativeWritableBufferImpl(
@@ -58,7 +57,6 @@ final class BBNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl {
     this.capacityBytes = capacityBytes;
     this.typeId = removeNnBuf(typeId) | BYTEBUF | BUFFER | NONNATIVE;
     this.cumOffsetBytes = cumOffsetBytes;
-    this.regionOffsetBytes = 0;
     this.memReqSvr = memReqSvr;
     this.byteBuf = byteBuf;
   }
@@ -69,19 +67,18 @@ final class BBNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl {
       final long capacityBytes,
       final boolean readOnly,
       final ByteOrder byteOrder) {
-    this.regionOffsetBytes = regionOffsetBytes;
     final long newOffsetBytes = offsetBytes + regionOffsetBytes;
-    cumOffsetBytes += regionOffsetBytes;
+    final long newCumOffsetBytes = cumOffsetBytes + regionOffsetBytes;
     int typeIdOut = removeNnBuf(typeId) | BUFFER | REGION | (readOnly ? READONLY : 0);
 
     if (Util.isNativeByteOrder(byteOrder)) {
       typeIdOut |= NATIVE;
       return new BBWritableBufferImpl(
-          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr, byteBuf);
     } else {
       typeIdOut |= NONNATIVE;
       return new BBNonNativeWritableBufferImpl(
-          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr, byteBuf);
     }
   }
 
@@ -138,17 +135,11 @@ final class BBNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl {
   }
 
   @Override
-  public long getOffset() {
+  public long getTotalOffset() {
     assertValid();
     return offsetBytes;
   }
 
-  @Override
-  public long getRegionOffset() {
-    assertValid();
-    return regionOffsetBytes;
-  }
-
   @Override
   int getTypeId() {
     assertValid();
@@ -161,4 +152,10 @@ final class BBNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl {
     return unsafeObj;
   }
 
+  @Override
+  public ByteBuffer getByteBuffer() {
+    assertValid();
+    return byteBuf;
+  }
+
 }
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableMemoryImpl.java
index 6ea83f9..80604b4 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableMemoryImpl.java
@@ -39,7 +39,6 @@ final class BBNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl {
   private final long capacityBytes;
   private final int typeId;
   private long cumOffsetBytes;
-  private long regionOffsetBytes;
   private final MemoryRequestServer memReqSvr;
 
   BBNonNativeWritableMemoryImpl(
@@ -58,7 +57,6 @@ final class BBNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl {
     this.capacityBytes = capacityBytes;
     this.typeId = removeNnBuf(typeId) | BYTEBUF | MEMORY | NONNATIVE;
     this.cumOffsetBytes = cumOffsetBytes;
-    this.regionOffsetBytes = 0;
     this.memReqSvr = memReqSvr;
     this.byteBuf = byteBuf;
   }
@@ -69,19 +67,18 @@ final class BBNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl {
       final long capacityBytes,
       final boolean readOnly,
       final ByteOrder byteOrder) {
-    this.regionOffsetBytes = regionOffsetBytes;
     final long newOffsetBytes = offsetBytes + regionOffsetBytes;
-    cumOffsetBytes += regionOffsetBytes;
+    final long newCumOffsetBytes = cumOffsetBytes + regionOffsetBytes;
     int typeIdOut = removeNnBuf(typeId) | MEMORY | REGION | (readOnly ? READONLY : 0);
 
     if (Util.isNativeByteOrder(byteOrder)) {
       typeIdOut |= NATIVE;
       return new BBWritableMemoryImpl(
-          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr, byteBuf);
     } else {
       typeIdOut |= NONNATIVE;
       return new BBNonNativeWritableMemoryImpl(
-          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr, byteBuf);
     }
   }
 
@@ -123,17 +120,11 @@ final class BBNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl {
   }
 
   @Override
-  public long getOffset() {
+  public long getTotalOffset() {
     assertValid();
     return offsetBytes;
   }
 
-  @Override
-  public long getRegionOffset() {
-    assertValid();
-    return regionOffsetBytes;
-  }
-
   @Override
   int getTypeId() {
     assertValid();
@@ -146,4 +137,10 @@ final class BBNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl {
     return unsafeObj;
   }
 
+  @Override
+  public ByteBuffer getByteBuffer() {
+    assertValid();
+    return byteBuf;
+  }
+
 }
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableBufferImpl.java
index a05eedc..fcd47f3 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableBufferImpl.java
@@ -32,14 +32,13 @@ import org.apache.datasketches.memory.WritableBuffer;
  * @author Lee Rhodes
  */
 final class BBWritableBufferImpl extends NativeWritableBufferImpl {
-  private final ByteBuffer byteBuf; //holds a reference to a ByteBuffer until we are done with it.
+  private final ByteBuffer byteBuf;    //holds a reference to a ByteBuffer until we are done with it.
   private final Object unsafeObj;
-  private final long nativeBaseOffset;
-  private final long offsetBytes;
+  private final long nativeBaseOffset; //raw off-heap address of root allocation (whether direct or ByteBuffer)
+  private final long offsetBytes;      //from the root resource including original ByteBuffer position or split offset
   private final long capacityBytes;
   private final int typeId;
-  private long cumOffsetBytes;
-  private long regionOffsetBytes;
+  private long cumOffsetBytes;         //includes array header if heap and nativeBaseOffset if off-heap
   private final MemoryRequestServer memReqSvr;
 
   BBWritableBufferImpl(
@@ -58,7 +57,6 @@ final class BBWritableBufferImpl extends NativeWritableBufferImpl {
     this.capacityBytes = capacityBytes;
     this.typeId = removeNnBuf(typeId) | BYTEBUF | BUFFER | NATIVE;
     this.cumOffsetBytes = cumOffsetBytes;
-    this.regionOffsetBytes = 0;
     this.memReqSvr = memReqSvr;
     this.byteBuf = byteBuf;
   }
@@ -69,19 +67,18 @@ final class BBWritableBufferImpl extends NativeWritableBufferImpl {
       final long capacityBytes,
       final boolean readOnly,
       final ByteOrder byteOrder) {
-    this.regionOffsetBytes = regionOffsetBytes;
     final long newOffsetBytes = offsetBytes + regionOffsetBytes;
-    cumOffsetBytes += regionOffsetBytes;
+    final long newCumOffsetBytes = cumOffsetBytes + regionOffsetBytes;
     int typeIdOut = removeNnBuf(typeId) | BUFFER | REGION | (readOnly ? READONLY : 0);
 
     if (Util.isNativeByteOrder(byteOrder)) {
       typeIdOut |= NATIVE;
       return new BBWritableBufferImpl(
-          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr, byteBuf);
     } else {
       typeIdOut |= NONNATIVE;
       return new BBNonNativeWritableBufferImpl(
-          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr, byteBuf);
     }
   }
 
@@ -138,17 +135,11 @@ final class BBWritableBufferImpl extends NativeWritableBufferImpl {
   }
 
   @Override
-  public long getOffset() {
+  public long getTotalOffset() {
     assertValid();
     return offsetBytes;
   }
 
-  @Override
-  public long getRegionOffset() {
-    assertValid();
-    return regionOffsetBytes;
-  }
-
   @Override
   int getTypeId() {
     assertValid();
@@ -161,4 +152,10 @@ final class BBWritableBufferImpl extends NativeWritableBufferImpl {
     return unsafeObj;
   }
 
+  @Override
+  public ByteBuffer getByteBuffer() {
+    assertValid();
+    return byteBuf;
+  }
+
 }
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableMemoryImpl.java
index 9c0cf14..c80bcef 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableMemoryImpl.java
@@ -34,12 +34,11 @@ import org.apache.datasketches.memory.WritableMemory;
 final class BBWritableMemoryImpl extends NativeWritableMemoryImpl {
   private final ByteBuffer byteBuf; //holds a reference to a ByteBuffer until we are done with it.
   private final Object unsafeObj;
-  private final long nativeBaseOffset;
-  private final long offsetBytes;
+  private final long nativeBaseOffset; //raw off-heap address of root allocation (whether direct or ByteBuffer)
+  private final long offsetBytes;      //from the root resource including original ByteBuffer position or region offset
   private final long capacityBytes;
   private final int typeId;
-  private long cumOffsetBytes;
-  private long regionOffsetBytes;
+  private long cumOffsetBytes;         //includes array header if heap and nativeBaseOffset if off-heap
   private final MemoryRequestServer memReqSvr;
 
   BBWritableMemoryImpl(
@@ -58,7 +57,6 @@ final class BBWritableMemoryImpl extends NativeWritableMemoryImpl {
     this.capacityBytes = capacityBytes;
     this.typeId = removeNnBuf(typeId) | BYTEBUF | MEMORY | NATIVE;
     this.cumOffsetBytes = cumOffsetBytes;
-    this.regionOffsetBytes = 0;
     this.memReqSvr = memReqSvr;
     this.byteBuf = byteBuf;
   }
@@ -69,19 +67,18 @@ final class BBWritableMemoryImpl extends NativeWritableMemoryImpl {
       final long capacityBytes,
       final boolean readOnly,
       final ByteOrder byteOrder) {
-    this.regionOffsetBytes = regionOffsetBytes;
     final long newOffsetBytes = offsetBytes + regionOffsetBytes;
-    cumOffsetBytes += regionOffsetBytes;
+    final long newCumOffsetBytes = cumOffsetBytes + regionOffsetBytes;
     int typeIdOut = removeNnBuf(typeId) | MEMORY | REGION | (readOnly ? READONLY : 0);
 
     if (Util.isNativeByteOrder(byteOrder)) {
       typeIdOut |= NATIVE;
       return new BBWritableMemoryImpl(
-          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr, byteBuf);
     } else {
       typeIdOut |= NONNATIVE;
       return new BBNonNativeWritableMemoryImpl(
-          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, byteBuf);
+          unsafeObj, nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr, byteBuf);
     }
   }
 
@@ -123,17 +120,11 @@ final class BBWritableMemoryImpl extends NativeWritableMemoryImpl {
   }
 
   @Override
-  public long getOffset() {
+  public long getTotalOffset() {
     assertValid();
     return offsetBytes;
   }
 
-  @Override
-  public long getRegionOffset() {
-    assertValid();
-    return regionOffsetBytes;
-  }
-
   @Override
   int getTypeId() {
     assertValid();
@@ -146,4 +137,9 @@ final class BBWritableMemoryImpl extends NativeWritableMemoryImpl {
     return unsafeObj;
   }
 
+  @Override
+  public ByteBuffer getByteBuffer() {
+    assertValid();
+    return byteBuf;
+  }
 }
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
index a63343f..fa75de8 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
@@ -141,6 +141,28 @@ public abstract class BaseStateImpl implements BaseState {
     return null;
   }
 
+  /**
+   * Gets the cumulative offset in bytes of this object from the backing resource.
+   * This offset may also include other offset components such as the native off-heap
+   * memory address, DirectByteBuffer split offsets, region offsets, and unsafe arrayBaseOffsets.
+   *
+   * @return the cumulative offset in bytes of this object from the backing resource.
+   */
+  abstract long getCumulativeOffset();
+
+  /**
+   * Gets the cumulative offset in bytes of this object from the backing resource including the given
+   * localOffsetBytes. This offset may also include other offset components such as the native off-heap
+   * memory address, DirectByteBuffer split offsets, region offsets, and object arrayBaseOffsets.
+   *
+   * @param localOffsetBytes offset to be added to the cumulative offset.
+   * @return the cumulative offset in bytes of this object from the backing resource including the
+   * given offsetBytes.
+   */
+  public long getCumulativeOffset(long localOffsetBytes) {
+    return getCumulativeOffset() + localOffsetBytes;
+  }
+
   //MONITORING
 
   /**
@@ -183,10 +205,8 @@ public abstract class BaseStateImpl implements BaseState {
   //Overridden by ByteBuffer, Direct and Map leafs
   abstract long getNativeBaseOffset();
 
-  abstract long getOffset();
-
   @Override
-  public final ByteOrder getTypeByteOrder() {
+  public final ByteOrder getByteOrder() {
     return isNonNativeType(getTypeId()) ? Util.NON_NATIVE_BYTE_ORDER : ByteOrder.nativeOrder();
   }
 
@@ -222,7 +242,7 @@ public abstract class BaseStateImpl implements BaseState {
 
   @Override
   public final boolean isByteOrderCompatible(final ByteOrder byteOrder) {
-    final ByteOrder typeBO = getTypeByteOrder();
+    final ByteOrder typeBO = getByteOrder();
     return typeBO == ByteOrder.nativeOrder() && typeBO == byteOrder;
   }
 
@@ -350,13 +370,13 @@ public abstract class BaseStateImpl implements BaseState {
     sb.append("UnsafeObj, hashCode : ").append(uObjStr).append(LS);
     sb.append("UnsafeObjHeader     : ").append(uObjHeader).append(LS);
     sb.append("ByteBuf, hashCode   : ").append(bbStr).append(LS);
-    sb.append("RegionOffset        : ").append(state.getRegionOffset()).append(LS);
+    sb.append("RegionOffset        : ").append(state.getTotalOffset()).append(LS);
     sb.append("Capacity            : ").append(capacity).append(LS);
     sb.append("CumBaseOffset       : ").append(cumBaseOffset).append(LS);
     sb.append("MemReq, hashCode    : ").append(memReqStr).append(LS);
     sb.append("Valid               : ").append(state.isValid()).append(LS);
     sb.append("Read Only           : ").append(state.isReadOnly()).append(LS);
-    sb.append("Type Byte Order     : ").append(state.getTypeByteOrder().toString()).append(LS);
+    sb.append("Type Byte Order     : ").append(state.getByteOrder().toString()).append(LS);
     sb.append("Native Byte Order   : ").append(ByteOrder.nativeOrder().toString()).append(LS);
     sb.append("JDK Runtime Version : ").append(UnsafeUtil.JDK).append(LS);
     //Data detail
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
index abbb9ac..d5f95f8 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
@@ -77,7 +77,7 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
       final MemoryRequestServer memReqSvr) {
     final AccessByteBuffer abb = new AccessByteBuffer(byteBuf);
     final int typeId = (abb.resourceReadOnly || localReadOnly) ? READONLY : 0;
-    final long cumOffsetBytes = 0;
+    final long cumOffsetBytes = abb.initialCumOffset;
     final BaseWritableBufferImpl bwbi = Util.isNativeByteOrder(byteOrder)
         ? new BBWritableBufferImpl(abb.unsafeObj, abb.nativeBaseOffset,
             abb.offsetBytes, abb.capacityBytes, typeId, cumOffsetBytes, memReqSvr, byteBuf)
@@ -90,7 +90,7 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
   //REGIONS
   @Override
   public Buffer region() {
-    return writableRegionImpl(getPosition(), getEnd() - getPosition(), true, getTypeByteOrder());
+    return writableRegionImpl(getPosition(), getEnd() - getPosition(), true, getByteOrder());
   }
 
   @Override
@@ -102,7 +102,7 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
 
   @Override
   public WritableBuffer writableRegion() {
-    return writableRegionImpl(getPosition(), getEnd() - getPosition(), false, getTypeByteOrder());
+    return writableRegionImpl(getPosition(), getEnd() - getPosition(), false, getByteOrder());
   }
 
   @Override
@@ -130,7 +130,7 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
   //DUPLICATES
   @Override
   public Buffer duplicate() {
-    return writableDuplicateImpl(true, getTypeByteOrder());
+    return writableDuplicateImpl(true, getByteOrder());
   }
 
   @Override
@@ -140,7 +140,7 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
 
   @Override
   public WritableBuffer writableDuplicate() {
-    return writableDuplicateImpl(false, getTypeByteOrder());
+    return writableDuplicateImpl(false, getByteOrder());
   }
 
   @Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java
index 7b07234..4394355 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java
@@ -36,7 +36,6 @@ final class DirectNonNativeWritableBufferImpl extends NonNativeWritableBufferImp
   private final long capacityBytes;
   private final int typeId;
   private long cumOffsetBytes;
-  private long regionOffsetBytes;
   private final MemoryRequestServer memReqSvr;
   private final StepBoolean valid; //a reference only
 
@@ -54,7 +53,6 @@ final class DirectNonNativeWritableBufferImpl extends NonNativeWritableBufferImp
     this.capacityBytes = capacityBytes;
     this.typeId = removeNnBuf(typeId) | DIRECT | BUFFER | NONNATIVE; //initially cannot be ReadOnly
     this.cumOffsetBytes = cumOffsetBytes;
-    this.regionOffsetBytes = 0;
     this.memReqSvr = memReqSvr;
     this.valid = valid;
   }
@@ -65,18 +63,17 @@ final class DirectNonNativeWritableBufferImpl extends NonNativeWritableBufferImp
       final long capacityBytes,
       final boolean readOnly,
       final ByteOrder byteOrder) {
-    this.regionOffsetBytes = regionOffsetBytes;
     final long newOffsetBytes = offsetBytes + regionOffsetBytes;
-    cumOffsetBytes += regionOffsetBytes;
+    final long newCumOffsetBytes = cumOffsetBytes + regionOffsetBytes;
     int typeIdOut = removeNnBuf(typeId) | BUFFER | REGION | (readOnly ? READONLY : 0);
     if (Util.isNativeByteOrder(byteOrder)) {
       typeIdOut |= NATIVE;
       return new DirectWritableBufferImpl(
-          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr, valid);
     } else {
       typeIdOut |= NONNATIVE;
       return new DirectNonNativeWritableBufferImpl(
-          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr, valid);
     }
   }
 
@@ -138,17 +135,11 @@ final class DirectNonNativeWritableBufferImpl extends NonNativeWritableBufferImp
   }
 
   @Override
-  public long getOffset() {
+  public long getTotalOffset() {
     assertValid();
     return offsetBytes;
   }
 
-  @Override
-  public long getRegionOffset() {
-    assertValid();
-    return regionOffsetBytes;
-  }
-
   @Override
   int getTypeId() {
     assertValid();
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableMemoryImpl.java
index f5bb988..9d26441 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableMemoryImpl.java
@@ -36,7 +36,6 @@ final class DirectNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImp
   private final long capacityBytes;
   private final int typeId;
   private long cumOffsetBytes;
-  private long regionOffsetBytes;
   private final MemoryRequestServer memReqSvr;
   private final StepBoolean valid; //a reference only
 
@@ -54,7 +53,6 @@ final class DirectNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImp
     this.capacityBytes = capacityBytes;
     this.typeId = removeNnBuf(typeId) | DIRECT | MEMORY | NONNATIVE; //initially cannot be ReadOnly
     this.cumOffsetBytes = cumOffsetBytes;
-    this.regionOffsetBytes = 0;
     this.memReqSvr = memReqSvr;
     this.valid = valid;
   }
@@ -65,19 +63,18 @@ final class DirectNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImp
       final long capacityBytes,
       final boolean readOnly,
       final ByteOrder byteOrder) {
-    this.regionOffsetBytes = regionOffsetBytes;
     final long newOffsetBytes = offsetBytes + regionOffsetBytes;
-    cumOffsetBytes += regionOffsetBytes;
+    final long newCumOffsetBytes = cumOffsetBytes + regionOffsetBytes;
     int typeIdOut = removeNnBuf(typeId) | MEMORY | REGION | (readOnly ? READONLY : 0);
 
     if (Util.isNativeByteOrder(byteOrder)) {
       typeIdOut |= NATIVE;
       return new DirectWritableMemoryImpl(
-          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr, valid);
     } else {
       typeIdOut |= NONNATIVE;
       return new DirectNonNativeWritableMemoryImpl(
-          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr, valid);
     }
   }
 
@@ -124,17 +121,11 @@ final class DirectNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImp
   }
 
   @Override
-  public long getOffset() {
+  public long getTotalOffset() {
     assertValid();
     return offsetBytes;
   }
 
-  @Override
-  public long getRegionOffset() {
-    assertValid();
-    return regionOffsetBytes;
-  }
-
   @Override
   int getTypeId() {
     assertValid();
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java
index c8147e5..f338c54 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java
@@ -36,7 +36,6 @@ final class DirectWritableBufferImpl extends NativeWritableBufferImpl {
   private final long capacityBytes;
   private final int typeId;
   private long cumOffsetBytes;
-  private long regionOffsetBytes;
   private final MemoryRequestServer memReqSvr;
   private final StepBoolean valid; //a reference only
 
@@ -54,7 +53,6 @@ final class DirectWritableBufferImpl extends NativeWritableBufferImpl {
     this.capacityBytes = capacityBytes;
     this.typeId = removeNnBuf(typeId) | DIRECT | BUFFER | NATIVE; //initially cannot be ReadOnly
     this.cumOffsetBytes = cumOffsetBytes;
-    this.regionOffsetBytes = 0;
     this.memReqSvr = memReqSvr;
     this.valid = valid;
   }
@@ -65,19 +63,18 @@ final class DirectWritableBufferImpl extends NativeWritableBufferImpl {
       final long capacityBytes,
       final boolean readOnly,
       final ByteOrder byteOrder) {
-    this.regionOffsetBytes = regionOffsetBytes;
     final long newOffsetBytes = offsetBytes + regionOffsetBytes;
-    cumOffsetBytes += regionOffsetBytes;
+    final long newCumOffsetBytes = cumOffsetBytes + regionOffsetBytes;
     int typeIdOut = removeNnBuf(typeId) | BUFFER | REGION | (readOnly ? READONLY : 0);
 
     if (Util.isNativeByteOrder(byteOrder)) {
       typeIdOut |= NATIVE;
       return new DirectWritableBufferImpl(
-          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr, valid);
     } else {
       typeIdOut |= NONNATIVE;
       return new DirectNonNativeWritableBufferImpl(
-          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr, valid);
     }
   }
 
@@ -139,17 +136,11 @@ final class DirectWritableBufferImpl extends NativeWritableBufferImpl {
   }
 
   @Override
-  public long getOffset() {
+  public long getTotalOffset() {
     assertValid();
     return offsetBytes;
   }
 
-  @Override
-  public long getRegionOffset() {
-    assertValid();
-    return regionOffsetBytes;
-  }
-
   @Override
   int getTypeId() {
     assertValid();
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableMemoryImpl.java
index 8ff0961..f4162a7 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableMemoryImpl.java
@@ -36,7 +36,6 @@ final class DirectWritableMemoryImpl extends NativeWritableMemoryImpl {
   private final long capacityBytes;
   private final int typeId;
   private long cumOffsetBytes;
-  private long regionOffsetBytes;
   private final MemoryRequestServer memReqSvr;
   private final StepBoolean valid; //a reference only
 
@@ -54,7 +53,6 @@ final class DirectWritableMemoryImpl extends NativeWritableMemoryImpl {
     this.capacityBytes = capacityBytes;
     this.typeId = removeNnBuf(typeId) | DIRECT | MEMORY | NATIVE; //initially cannot be ReadOnly
     this.cumOffsetBytes = cumOffsetBytes;
-    this.regionOffsetBytes = 0;
     this.memReqSvr = memReqSvr;
     this.valid = valid;
   }
@@ -65,19 +63,18 @@ final class DirectWritableMemoryImpl extends NativeWritableMemoryImpl {
       final long capacityBytes,
       final boolean readOnly,
       final ByteOrder byteOrder) {
-    //this.regionOffsetBytes = regionOffsetBytes;
     final long newOffsetBytes = offsetBytes + regionOffsetBytes;
-    cumOffsetBytes += regionOffsetBytes;
+    final long newCumOffsetBytes = cumOffsetBytes + regionOffsetBytes;
     int typeIdOut = removeNnBuf(typeId) | MEMORY | REGION | (readOnly ? READONLY : 0);
 
     if (Util.isNativeByteOrder(byteOrder)) {
       typeIdOut |= NATIVE;
       return new DirectWritableMemoryImpl(
-          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr, valid);
     } else {
       typeIdOut |= NONNATIVE;
       return new DirectNonNativeWritableMemoryImpl(
-          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr, valid);
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr, valid);
     }
   }
 
@@ -124,17 +121,11 @@ final class DirectWritableMemoryImpl extends NativeWritableMemoryImpl {
   }
 
   @Override
-  public long getOffset() {
+  public long getTotalOffset() {
     assertValid();
     return offsetBytes;
   }
 
-  @Override
-  public long getRegionOffset() {
-    assertValid();
-    return regionOffsetBytes;
-  }
-
   @Override
   int getTypeId() {
     assertValid();
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java
index 91d98fa..3b1386c 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java
@@ -36,7 +36,6 @@ final class HeapNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl
   private final long capacityBytes;
   private final int typeId;
   private long cumOffsetBytes;
-  private long regionOffsetBytes;
   private final MemoryRequestServer memReqSvr;
 
   HeapNonNativeWritableBufferImpl(
@@ -52,7 +51,6 @@ final class HeapNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl
     this.capacityBytes = capacityBytes;
     this.typeId = removeNnBuf(typeId) | HEAP | BUFFER | NONNATIVE;
     this.cumOffsetBytes = cumOffsetBytes;
-    this.regionOffsetBytes = 0;
     this.memReqSvr = memReqSvr;
   }
 
@@ -62,19 +60,18 @@ final class HeapNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl
       final long capacityBytes,
       final boolean readOnly,
       final ByteOrder byteOrder) {
-    this.regionOffsetBytes = regionOffsetBytes;
     final long newOffsetBytes = offsetBytes + regionOffsetBytes;
-    this.cumOffsetBytes += regionOffsetBytes;
+    final long newCumOffsetBytes = cumOffsetBytes + regionOffsetBytes;
     int typeIdOut = removeNnBuf(typeId) | BUFFER | REGION | (readOnly ? READONLY : 0);
 
     if (Util.isNativeByteOrder(byteOrder)) {
       typeIdOut |= NATIVE;
       return new HeapWritableBufferImpl(
-          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
+          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr);
     } else {
       typeIdOut |= NONNATIVE;
       return new HeapNonNativeWritableBufferImpl(
-          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
+          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr);
     }
   }
 
@@ -131,17 +128,11 @@ final class HeapNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl
   }
 
   @Override
-  public long getOffset() {
+  public long getTotalOffset() {
     assertValid();
     return offsetBytes;
   }
 
-  @Override
-  public long getRegionOffset() {
-    assertValid();
-    return regionOffsetBytes;
-  }
-
   @Override
   int getTypeId() {
     assertValid();
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java
index 5ebe8db..e528cef 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java
@@ -36,7 +36,6 @@ final class HeapNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl
   private final long capacityBytes;
   private final int typeId;
   private long cumOffsetBytes;
-  private long regionOffsetBytes;
   private final MemoryRequestServer memReqSvr;
 
   HeapNonNativeWritableMemoryImpl(
@@ -52,7 +51,6 @@ final class HeapNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl
     this.capacityBytes = capacityBytes;
     this.typeId = removeNnBuf(typeId) | HEAP | MEMORY | NONNATIVE;
     this.cumOffsetBytes = cumOffsetBytes;
-    this.regionOffsetBytes = 0;
     this.memReqSvr = memReqSvr;
   }
 
@@ -62,19 +60,18 @@ final class HeapNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl
       final long capacityBytes,
       final boolean readOnly,
       final ByteOrder byteOrder) {
-    this.regionOffsetBytes = regionOffsetBytes;
     final long newOffsetBytes = offsetBytes + regionOffsetBytes;
-    this.cumOffsetBytes += regionOffsetBytes;
+    final long newCumOffsetBytes = cumOffsetBytes + regionOffsetBytes;
     int typeIdOut = removeNnBuf(typeId) | MEMORY | REGION | (readOnly ? READONLY : 0);
 
     if (Util.isNativeByteOrder(byteOrder)) {
       typeIdOut |= NATIVE;
       return new HeapWritableMemoryImpl(
-          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
+          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr);
     } else {
       typeIdOut |= NONNATIVE;
       return new HeapNonNativeWritableMemoryImpl(
-          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
+          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr);
     }
   }
 
@@ -116,17 +113,11 @@ final class HeapNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl
   }
 
   @Override
-  public long getOffset() {
+  public long getTotalOffset() {
     assertValid();
     return offsetBytes;
   }
 
-  @Override
-  public long getRegionOffset() {
-    assertValid();
-    return regionOffsetBytes;
-  }
-
   @Override
   int getTypeId() {
     assertValid();
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java
index e54a3cf..33d8170 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java
@@ -36,7 +36,6 @@ final class HeapWritableBufferImpl extends NativeWritableBufferImpl {
   private final long capacityBytes;
   private final int typeId;
   private long cumOffsetBytes;
-  private long regionOffsetBytes;
   private final MemoryRequestServer memReqSvr;
 
   HeapWritableBufferImpl(
@@ -52,7 +51,6 @@ final class HeapWritableBufferImpl extends NativeWritableBufferImpl {
     this.capacityBytes = capacityBytes;
     this.typeId = removeNnBuf(typeId) | HEAP | BUFFER | NATIVE;
     this.cumOffsetBytes = cumOffsetBytes;
-    this.regionOffsetBytes = 0;
     this.memReqSvr = memReqSvr;
   }
 
@@ -62,19 +60,18 @@ final class HeapWritableBufferImpl extends NativeWritableBufferImpl {
       final long capacityBytes,
       final boolean readOnly,
       final ByteOrder byteOrder) {
-    this.regionOffsetBytes = regionOffsetBytes;
     final long newOffsetBytes = offsetBytes + regionOffsetBytes;
-    this.cumOffsetBytes += regionOffsetBytes;
+    final long newCumOffsetBytes = cumOffsetBytes + regionOffsetBytes;
     int typeIdOut = removeNnBuf(typeId) | BUFFER | REGION | (readOnly ? READONLY : 0);
 
     if (Util.isNativeByteOrder(byteOrder)) {
       typeIdOut |= NATIVE;
       return new HeapWritableBufferImpl(
-          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
+          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr);
     } else {
       typeIdOut |= NONNATIVE;
       return new HeapNonNativeWritableBufferImpl(
-          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
+          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr);
     }
   }
 
@@ -131,17 +128,11 @@ final class HeapWritableBufferImpl extends NativeWritableBufferImpl {
   }
 
   @Override
-  public long getOffset() {
+  public long getTotalOffset() {
     assertValid();
     return offsetBytes;
   }
 
-  @Override
-  public long getRegionOffset() {
-    assertValid();
-    return regionOffsetBytes;
-  }
-
   @Override
   int getTypeId() {
     assertValid();
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java
index 2da356c..d70ac99 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java
@@ -36,7 +36,6 @@ final class HeapWritableMemoryImpl extends NativeWritableMemoryImpl {
   private final long capacityBytes;
   private final int typeId;
   private long cumOffsetBytes;
-  private long regionOffsetBytes;
   private final MemoryRequestServer memReqSvr;
 
   HeapWritableMemoryImpl(
@@ -52,7 +51,6 @@ final class HeapWritableMemoryImpl extends NativeWritableMemoryImpl {
     this.capacityBytes = capacityBytes;
     this.typeId = removeNnBuf(typeId) | HEAP | MEMORY | NATIVE;
     this.cumOffsetBytes = cumOffsetBytes;
-    this.regionOffsetBytes = 0;
     this.memReqSvr = memReqSvr;
   }
 
@@ -62,19 +60,18 @@ final class HeapWritableMemoryImpl extends NativeWritableMemoryImpl {
       final long capacityBytes,
       final boolean readOnly,
       final ByteOrder byteOrder) {
-    this.regionOffsetBytes = regionOffsetBytes;
     final long newOffsetBytes = offsetBytes + regionOffsetBytes;
-    cumOffsetBytes += regionOffsetBytes;
+    final long newCumOffsetBytes = cumOffsetBytes + regionOffsetBytes;
     int typeIdOut = removeNnBuf(typeId) | MEMORY | REGION | (readOnly ? READONLY : 0);
 
     if (Util.isNativeByteOrder(byteOrder)) {
       typeIdOut |= NATIVE;
       return new HeapWritableMemoryImpl(
-          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
+          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr);
     } else {
       typeIdOut |= NONNATIVE;
       return new HeapNonNativeWritableMemoryImpl(
-          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, memReqSvr);
+          unsafeObj, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, memReqSvr);
     }
   }
 
@@ -116,17 +113,11 @@ final class HeapWritableMemoryImpl extends NativeWritableMemoryImpl {
   }
 
   @Override
-  public long getOffset() {
+  public long getTotalOffset() {
     assertValid();
     return offsetBytes;
   }
 
-  @Override
-  public long getRegionOffset() {
-    assertValid();
-    return regionOffsetBytes;
-  }
-
   @Override
   int getTypeId() {
     assertValid();
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java
index b5333a2..00eb965 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java
@@ -36,7 +36,6 @@ final class MapNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl {
   private final long capacityBytes;
   private final int typeId;
   private long cumOffsetBytes;
-  private long regionOffsetBytes;
   private final StepBoolean valid; //a reference only
 
   MapNonNativeWritableBufferImpl(
@@ -52,7 +51,6 @@ final class MapNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl {
     this.capacityBytes = capacityBytes;
     this.typeId = removeNnBuf(typeId) | MAP | BUFFER | NONNATIVE;
     this.cumOffsetBytes = cumOffsetBytes;
-    this.regionOffsetBytes = 0;
     this.valid = valid;
   }
 
@@ -62,19 +60,18 @@ final class MapNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl {
       final long capacityBytes,
       final boolean readOnly,
       final ByteOrder byteOrder) {
-    this.regionOffsetBytes = regionOffsetBytes;
     final long newOffsetBytes = offsetBytes + regionOffsetBytes;
-    cumOffsetBytes += regionOffsetBytes;
+    final long newCumOffsetBytes = cumOffsetBytes + regionOffsetBytes;
     int typeIdOut = removeNnBuf(typeId) | MAP | REGION | (readOnly ? READONLY : 0);
 
     if (Util.isNativeByteOrder(byteOrder)) {
       typeIdOut |= NATIVE;
       return new MapWritableBufferImpl(
-          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, valid);
     } else {
       typeIdOut |= NONNATIVE;
       return new MapNonNativeWritableBufferImpl(
-          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, valid);
     }
   }
 
@@ -136,17 +133,11 @@ final class MapNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl {
   }
 
   @Override
-  public long getOffset() {
+  public long getTotalOffset() {
     assertValid();
     return offsetBytes;
   }
 
-  @Override
-  public long getRegionOffset() {
-    assertValid();
-    return regionOffsetBytes;
-  }
-
   @Override
   int getTypeId() {
     assertValid();
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableMemoryImpl.java
index ce53e6f..9a4ace9 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableMemoryImpl.java
@@ -36,7 +36,6 @@ final class MapNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl {
   private final long capacityBytes;
   private final int typeId;
   private long cumOffsetBytes;
-  private long regionOffsetBytes;
   private final StepBoolean valid; //a reference only
 
   MapNonNativeWritableMemoryImpl(
@@ -52,7 +51,6 @@ final class MapNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl {
     this.capacityBytes = capacityBytes;
     this.typeId = removeNnBuf(typeId) | MAP | MEMORY | NONNATIVE;
     this.cumOffsetBytes = cumOffsetBytes;
-    this.regionOffsetBytes = 0;
     this.valid = valid;
   }
 
@@ -62,19 +60,18 @@ final class MapNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl {
       final long capacityBytes,
       final boolean readOnly,
       final ByteOrder byteOrder) {
-    this.regionOffsetBytes = regionOffsetBytes;
     final long newOffsetBytes = offsetBytes + regionOffsetBytes;
-    cumOffsetBytes += regionOffsetBytes;
+    final long newCumOffsetBytes = cumOffsetBytes + regionOffsetBytes;
     int typeIdOut = removeNnBuf(typeId) | MAP | REGION | (readOnly ? READONLY : 0);
 
     if (Util.isNativeByteOrder(byteOrder)) {
       typeIdOut |= NATIVE;
       return new MapWritableMemoryImpl(
-          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, valid);
     } else {
       typeIdOut |= NONNATIVE;
       return new MapNonNativeWritableMemoryImpl(
-          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, valid);
     }
   }
 
@@ -121,17 +118,11 @@ final class MapNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl {
   }
 
   @Override
-  public long getOffset() {
+  public long getTotalOffset() {
     assertValid();
     return offsetBytes;
   }
 
-  @Override
-  public long getRegionOffset() {
-    assertValid();
-    return regionOffsetBytes;
-  }
-
   @Override
   int getTypeId() {
     assertValid();
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java
index dfc6017..51ba0db 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java
@@ -36,7 +36,6 @@ final class MapWritableBufferImpl extends NativeWritableBufferImpl {
   private final long capacityBytes;
   private final int typeId;
   private long cumOffsetBytes;
-  private long regionOffsetBytes;
   private final StepBoolean valid; //a reference only
 
   MapWritableBufferImpl(
@@ -52,7 +51,6 @@ final class MapWritableBufferImpl extends NativeWritableBufferImpl {
     this.capacityBytes = capacityBytes;
     this.typeId = removeNnBuf(typeId) | MAP | BUFFER | NATIVE;
     this.cumOffsetBytes = cumOffsetBytes;
-    this.regionOffsetBytes = 0;
     this.valid = valid;
   }
 
@@ -62,19 +60,18 @@ final class MapWritableBufferImpl extends NativeWritableBufferImpl {
       final long capacityBytes,
       final boolean readOnly,
       final ByteOrder byteOrder) {
-    this.regionOffsetBytes = regionOffsetBytes;
     final long newOffsetBytes = offsetBytes + regionOffsetBytes;
-    cumOffsetBytes += regionOffsetBytes;
+    final long newCumOffsetBytes = cumOffsetBytes + regionOffsetBytes;
     int typeIdOut = removeNnBuf(typeId) | MAP | REGION | (readOnly ? READONLY : 0);
 
     if (Util.isNativeByteOrder(byteOrder)) {
       typeIdOut |= NATIVE;
       return new MapWritableBufferImpl(
-          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, valid);
     } else {
       typeIdOut |= NONNATIVE;
       return new MapNonNativeWritableBufferImpl(
-          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, valid);
     }
   }
 
@@ -136,17 +133,11 @@ final class MapWritableBufferImpl extends NativeWritableBufferImpl {
   }
 
   @Override
-  public long getOffset() {
+  public long getTotalOffset() {
     assertValid();
     return offsetBytes;
   }
 
-  @Override
-  public long getRegionOffset() {
-    assertValid();
-    return regionOffsetBytes;
-  }
-
   @Override
   int getTypeId() {
     assertValid();
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java
index 3216a4f..2417281 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java
@@ -36,7 +36,6 @@ final class MapWritableMemoryImpl extends NativeWritableMemoryImpl {
   private final long capacityBytes;
   private final int typeId;
   private long cumOffsetBytes;
-  private long regionOffsetBytes;
   private final StepBoolean valid; //a reference only
 
   MapWritableMemoryImpl(
@@ -52,7 +51,6 @@ final class MapWritableMemoryImpl extends NativeWritableMemoryImpl {
     this.capacityBytes = capacityBytes;
     this.typeId = removeNnBuf(typeId) | MAP | MEMORY | NATIVE;
     this.cumOffsetBytes = cumOffsetBytes;
-    this.regionOffsetBytes = cumOffsetBytes - nativeBaseOffset;
     this.valid = valid;
   }
 
@@ -64,17 +62,17 @@ final class MapWritableMemoryImpl extends NativeWritableMemoryImpl {
       final ByteOrder byteOrder) {
     //this.regionOffsetBytes = regionOffsetBytes;
     final long newOffsetBytes = offsetBytes + regionOffsetBytes;
-    cumOffsetBytes += regionOffsetBytes;
+    final long newCumOffsetBytes = cumOffsetBytes + regionOffsetBytes;
     int typeIdOut = removeNnBuf(typeId) | MAP | REGION | (readOnly ? READONLY : 0);
 
     if (Util.isNativeByteOrder(byteOrder)) {
       typeIdOut |= NATIVE;
       return new MapWritableMemoryImpl(
-          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, valid);
     } else {
       typeIdOut |= NONNATIVE;
       return new MapNonNativeWritableMemoryImpl(
-          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, cumOffsetBytes, valid);
+          nativeBaseOffset, newOffsetBytes, capacityBytes, typeIdOut, newCumOffsetBytes, valid);
     }
   }
 
@@ -121,17 +119,11 @@ final class MapWritableMemoryImpl extends NativeWritableMemoryImpl {
   }
 
   @Override
-  public long getOffset() {
+  public long getTotalOffset() {
     assertValid();
     return offsetBytes;
   }
 
-  @Override
-  public long getRegionOffset() {
-    assertValid();
-    return regionOffsetBytes;
-  }
-
   @Override
   int getTypeId() {
     assertValid();
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AaByteBufferTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AaByteBufferTest.java
deleted file mode 100644
index 46ee5af..0000000
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AaByteBufferTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.datasketches.memory.internal;
-
-import java.nio.ByteBuffer;
-
-import org.apache.datasketches.memory.Memory;
-import org.testng.annotations.Test;
-
-public class AaByteBufferTest {
-
-  @Test
-  public void checkBB() {
-    byte[] byteArr = new byte[32];
-    int len = byteArr.length;
-    for (byte i = 0; i < len; i++) { byteArr[i] = i; }
-    ByteBuffer bb = ByteBuffer.wrap(byteArr);
-    Memory mem = Memory.wrap(bb);
-    for (int i = 0; i < len; i++) {
-      //System.out.println(mem.getByte(i));
-    }
-  }
-
-  @Test
-  public void checkHeap() {
-    byte[] byteArr = new byte[32];
-    int len = byteArr.length;
-    for (byte i = 0; i < len; i++) { byteArr[i] = i; }
-    Memory mem = Memory.wrap(byteArr);
-    for (int i = 0; i < len; i++) {
-      //System.out.println(mem.getByte(i));
-    }
-  }
-
-}
-
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
index 455ad3d..5845be2 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
@@ -62,22 +62,22 @@ public class AllocateDirectMapMemoryTest {
     try (MapHandle rh = Memory.map(file))
     {
       Memory mem = rh.get();
-      println("Mem Cap:    " + mem.getCapacity());
-      println("Native Off: " + ((BaseStateImpl)mem).getNativeBaseOffset());
-      println("Offset:     " + ((BaseStateImpl)mem).getOffset());
-      println("Cum Offset: " + mem.getCumulativeOffset(0));
-      println("Region Offset: " + mem.getRegionOffset());
+      println("Mem Cap:       " + mem.getCapacity());
+      println("Native Off:    " + ((BaseStateImpl)mem).getNativeBaseOffset());
+      println("Total Offset:  " + mem.getTotalOffset());
+      println("Cum Offset:    " + ((BaseStateImpl)mem).getCumulativeOffset(0));
+      println("Region Offset: " + mem.getTotalOffset());
       StringBuilder sb = new StringBuilder();
       mem.getCharsFromUtf8(43, 176, sb);
       println(sb.toString());
 
       println("");
       Memory mem2 = mem.region(43+76, 20);
-      println("Mem Cap: " + mem2.getCapacity());
-      println("Native Off: " + ((BaseStateImpl)mem).getNativeBaseOffset());
-      println("Offset:     " + ((BaseStateImpl)mem).getOffset());
-      println("Cum Offset: " + mem2.getCumulativeOffset(0));
-      println("Region Offset: " + mem2.getRegionOffset());
+      println("Mem Cap:       " + mem2.getCapacity());
+      println("Native Off:    " + ((BaseStateImpl)mem).getNativeBaseOffset());
+      println("Offset:        " + mem.getTotalOffset());
+      println("Cum Offset:    " + ((BaseStateImpl)mem2).getCumulativeOffset(0));
+      println("Region Offset: " + mem2.getTotalOffset());
       StringBuilder sb2 = new StringBuilder();
       mem2.getCharsFromUtf8(0, 12, sb2);
       println(sb2.toString());
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java
index 8aef3db..304027d 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java
@@ -38,7 +38,7 @@ import org.testng.annotations.Test;
 public class Buffer2Test {
 
   @Test
-  public void testWrapByteBuf() {
+  public void testWrapHeapByteBuf() {
     ByteBuffer bb = ByteBuffer.allocate(64).order(ByteOrder.nativeOrder());
 
     Byte b = 0;
@@ -330,7 +330,7 @@ public class Buffer2Test {
     }
     bb.position(10);
 
-    Buffer buffer = Buffer.wrap(bb.slice().order(ByteOrder.nativeOrder())); //slice = 54
+    Buffer buffer = Buffer.wrap(bb.slice().order(ByteOrder.nativeOrder())); //slice size = 54
     buffer.setPosition(30);//remaining = 24
     Buffer dupBuffer = buffer.duplicate(); //all 54
     Buffer regionBuffer = buffer.region(); //24
@@ -353,7 +353,7 @@ public class Buffer2Test {
     for (int i = 0; i < n; i++) { arr[i] = i; }
     Memory mem = Memory.wrap(arr);
     Buffer buf = mem.asBuffer();
-    Buffer reg = buf.region(n2 * 8, n2 * 8, buf.getTypeByteOrder()); //top half
+    Buffer reg = buf.region(n2 * 8, n2 * 8, buf.getByteOrder()); //top half
     for (int i = 0; i < n2; i++) {
       long v = reg.getLong(i * 8);
       long e = i + n2;
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferTest.java
index 64b3c77..73f02e0 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferTest.java
@@ -25,10 +25,10 @@ import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 import java.util.List;
 
-import org.apache.datasketches.memory.WritableHandle;
 import org.apache.datasketches.memory.Buffer;
 import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.WritableBuffer;
+import org.apache.datasketches.memory.WritableHandle;
 import org.apache.datasketches.memory.WritableMemory;
 import org.testng.annotations.Test;
 import org.testng.collections.Lists;
@@ -203,7 +203,7 @@ public class BufferTest {
     ByteBuffer bb = ByteBuffer.allocate(n * 8);
     bb.order(ByteOrder.BIG_ENDIAN);
     Buffer buf = Buffer.wrap(bb);
-    assertEquals(buf.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
+    assertEquals(buf.getByteOrder(), ByteOrder.BIG_ENDIAN);
   }
 
   @Test
@@ -262,20 +262,21 @@ public class BufferTest {
     int n = 16;
     int n2 = n / 2;
     long[] arr = new long[n];
-    for (int i = 0; i < n; i++) { arr[i] = i; }
-    WritableBuffer wbuf = WritableMemory.writableWrap(arr).asWritableBuffer();
+    for (int i = 0; i < n; i++) { arr[i] = i; } //0...n-1
+    WritableMemory mem = WritableMemory.writableWrap(arr);
+    WritableBuffer wbuf = mem.asWritableBuffer();
     for (int i = 0; i < n; i++) {
-      assertEquals(wbuf.getLong(), i); //write all
-      //println("" + wmem.getLong(i * 8));
+      assertEquals(wbuf.getLong(), i); //0...n-1
+      println("" + wbuf.getLong(i * 8));
     }
-    //println("");
+    println("");
     wbuf.setPosition(n2 * 8);
     WritableBuffer reg = wbuf.writableRegion();
     for (int i = 0; i < n2; i++) { reg.putLong(i); } //rewrite top half
     wbuf.resetPosition();
     for (int i = 0; i < n; i++) {
-      assertEquals(wbuf.getLong(), i % 8);
-      //println("" + wmem.getLong(i * 8));
+      println("" + wbuf.getLong(i * 8));
+      assertEquals(wbuf.getLong(), i % 8); //fail got 1 not 0
     }
   }
 
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/ExampleMemoryRequestServerTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/ExampleMemoryRequestServerTest.java
index 0cf345c..0ad16be 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/ExampleMemoryRequestServerTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/ExampleMemoryRequestServerTest.java
@@ -131,7 +131,7 @@ public class ExampleMemoryRequestServerTest {
 
     @Override
     public WritableMemory request(WritableMemory currentWMem, long capacityBytes) {
-     ByteOrder order = currentWMem.getTypeByteOrder();
+     ByteOrder order = currentWMem.getByteOrder();
      WritableHandle handle = WritableMemory.allocateDirect(capacityBytes, order, this);
      WritableMemory wmem = handle.getWritable();
      map.put(wmem, handle); //We track the newly allocated memory and its handle.
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/LeafImplTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/LeafImplTest.java
index f1ef17e..e0082ff 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/LeafImplTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/LeafImplTest.java
@@ -87,7 +87,7 @@ public class LeafImplTest {
     WritableMemory mem = WritableMemory.writableWrap(bb, NBO, dummyMemReqSvr);
     assertEquals(bb.isDirect(), mem.isDirect());
     assertNotNull(((BaseStateImpl)mem).getUnsafeObject());
-    checkCombinations(mem, off, cap, mem.isDirect(), mem.getTypeByteOrder(), true, true);
+    checkCombinations(mem, off, cap, mem.isDirect(), mem.getByteOrder(), true, true);
 
     //BB off heap, native order, has ByteBuffer, has MemReqSvr
     ByteBuffer dbb = ByteBuffer.allocateDirect((int)cap);
@@ -96,7 +96,7 @@ public class LeafImplTest {
     mem = WritableMemory.writableWrap(dbb, NBO, dummyMemReqSvr);
     assertEquals(dbb.isDirect(), mem.isDirect());
     assertNull(((BaseStateImpl)mem).getUnsafeObject());
-    checkCombinations(mem, off, cap,  mem.isDirect(), mem.getTypeByteOrder(), true, true);
+    checkCombinations(mem, off, cap,  mem.isDirect(), mem.getByteOrder(), true, true);
 
     //BB on heap, non native order, has ByteBuffer, has MemReqSvr
     bb = ByteBuffer.allocate((int)cap);
@@ -105,7 +105,7 @@ public class LeafImplTest {
     mem = WritableMemory.writableWrap(bb, NNBO, dummyMemReqSvr);
     assertEquals(bb.isDirect(), mem.isDirect());
     assertNotNull(((BaseStateImpl)mem).getUnsafeObject());
-    checkCombinations(mem, off, cap, mem.isDirect(), mem.getTypeByteOrder(), true, true);
+    checkCombinations(mem, off, cap, mem.isDirect(), mem.getByteOrder(), true, true);
 
     //BB off heap, non native order, has ByteBuffer, has MemReqSvr
     dbb = ByteBuffer.allocateDirect((int)cap);
@@ -114,7 +114,7 @@ public class LeafImplTest {
     mem = WritableMemory.writableWrap(dbb, NNBO, dummyMemReqSvr);
     assertEquals(dbb.isDirect(), mem.isDirect());
     assertNull(((BaseStateImpl)mem).getUnsafeObject());
-    checkCombinations(mem, off, cap,  mem.isDirect(), mem.getTypeByteOrder(), true, true);
+    checkCombinations(mem, off, cap,  mem.isDirect(), mem.getByteOrder(), true, true);
   }
 
   @Test
@@ -182,7 +182,7 @@ public class LeafImplTest {
     ByteBuffer bb = mem.getByteBuffer();
     assertTrue( hasByteBuffer ? bb != null : bb == null);
 
-    assertTrue(mem.getTypeByteOrder() == bo);
+    assertTrue(mem.getByteOrder() == bo);
 
     if (hasMemReqSvr) { assertTrue(mem.getMemoryRequestServer() instanceof DummyMemoryRequestServer); }
 
@@ -207,7 +207,7 @@ public class LeafImplTest {
     bb = buf.getByteBuffer();
     assertTrue(hasByteBuffer ? bb != null : bb == null);
 
-    assertTrue(buf.getTypeByteOrder() == bo);
+    assertTrue(buf.getByteOrder() == bo);
 
     if (hasMemReqSvr) { assertTrue(buf.getMemoryRequestServer() instanceof DummyMemoryRequestServer); }
 
@@ -232,7 +232,7 @@ public class LeafImplTest {
     bb = nnMem.getByteBuffer();
     assertTrue( hasByteBuffer ? bb != null : bb == null);
 
-    assertTrue(nnMem.getTypeByteOrder() == oo);
+    assertTrue(nnMem.getByteOrder() == oo);
 
     if (hasMemReqSvr) { assertTrue(nnMem.getMemoryRequestServer() instanceof DummyMemoryRequestServer); }
 
@@ -257,7 +257,7 @@ public class LeafImplTest {
     bb = nnBuf.getByteBuffer();
     assertTrue( hasByteBuffer ? bb != null : bb == null);
 
-    assertTrue(nnBuf.getTypeByteOrder() == oo);
+    assertTrue(nnBuf.getByteOrder() == oo);
 
     if (hasMemReqSvr) { assertTrue(nnBuf.getMemoryRequestServer() instanceof DummyMemoryRequestServer); }
 
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
index 045c59f..c8d985b 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
@@ -210,8 +210,8 @@ public class MemoryTest {
     ByteBuffer bb = ByteBuffer.allocate(n * 8);
     bb.order(ByteOrder.BIG_ENDIAN);
     Memory mem = Memory.wrap(bb);
-    assertFalse(mem.getTypeByteOrder() == ByteOrder.nativeOrder());
-    assertEquals(mem.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
+    assertFalse(mem.getByteOrder() == ByteOrder.nativeOrder());
+    assertEquals(mem.getByteOrder(), ByteOrder.BIG_ENDIAN);
   }
 
   @Test
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java
index b1fccf2..fe802f7 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java
@@ -233,7 +233,7 @@ public class NativeWritableBufferImplTest {
     try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
       WritableMemory wmem = wrh.getWritable();
       WritableBuffer wbuf = wmem.asWritableBuffer();
-      wbuf.writableRegion(1, 64, wbuf.getTypeByteOrder()); //wrong!
+      wbuf.writableRegion(1, 64, wbuf.getByteOrder()); //wrong!
     }
   }
 
@@ -476,9 +476,8 @@ public class NativeWritableBufferImplTest {
     WritableMemory wmem = WritableMemory.allocate(64);
     WritableMemory reg = wmem.writableRegion(32, 32);
     WritableBuffer buf = reg.asWritableBuffer();
-    assertEquals(buf.getRegionOffset(), 32);
-    assertEquals(buf.getRegionOffset(0), 32);
-    assertEquals(buf.getCumulativeOffset(0), 32 + 16);
+    assertEquals(buf.getTotalOffset(), 32);
+    assertEquals(((BaseStateImpl)buf).getCumulativeOffset(0), 32 + 16);
   }
 
   @Test
@@ -555,13 +554,13 @@ public class NativeWritableBufferImplTest {
     ByteBuffer bb = ByteBuffer.allocate(64);
     WritableBuffer wbuf = WritableBuffer.writableWrap(bb);
     @SuppressWarnings("unused")
-    WritableBuffer wreg = wbuf.writableRegion(0, 1, wbuf.getTypeByteOrder());
+    WritableBuffer wreg = wbuf.writableRegion(0, 1, wbuf.getByteOrder());
 
     try {
       Buffer buf = Buffer.wrap(bb);
       wbuf = (WritableBuffer) buf;
       @SuppressWarnings("unused")
-      WritableBuffer wreg2 = wbuf.writableRegion(0, 1, wbuf.getTypeByteOrder());
+      WritableBuffer wreg2 = wbuf.writableRegion(0, 1, wbuf.getByteOrder());
       Assert.fail();
     } catch (ReadOnlyException expected) {
       // ignore
@@ -572,7 +571,7 @@ public class NativeWritableBufferImplTest {
   public void checkZeroBuffer() {
     WritableMemory wmem = WritableMemory.allocate(8);
     WritableBuffer wbuf = wmem.asWritableBuffer();
-    WritableBuffer reg = wbuf.writableRegion(0, 0, wbuf.getTypeByteOrder());
+    WritableBuffer reg = wbuf.writableRegion(0, 0, wbuf.getByteOrder());
     assertEquals(reg.getCapacity(), 0);
   }
 
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java
index e6d13cc..4cca6f8 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java
@@ -654,9 +654,8 @@ public class NativeWritableMemoryImplTest {
   public void checkCumAndRegionOffset() {
     WritableMemory wmem = WritableMemory.allocate(64);
     WritableMemory reg = wmem.writableRegion(32, 32);
-    assertEquals(reg.getRegionOffset(), 32);
-    assertEquals(reg.getRegionOffset(0), 32);
-    assertEquals(reg.getCumulativeOffset(0), 32 + 16);
+    assertEquals(reg.getTotalOffset(), 32);
+    assertEquals(((BaseStateImpl)reg).getCumulativeOffset(0), 32 + 16);
 
   }
 
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImplTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImplTest.java
index 57d481a..d7f0421 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImplTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImplTest.java
@@ -239,10 +239,10 @@ public class NonNativeWritableBufferImplTest {
     WritableMemory wmem = WritableMemory.writableWrap(bArr, ByteOrder.BIG_ENDIAN);
     WritableBuffer wbuf = wmem.asWritableBuffer();
     WritableBuffer wdup = wbuf.writableDuplicate();
-    assertEquals(wdup.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
+    assertEquals(wdup.getByteOrder(), ByteOrder.BIG_ENDIAN);
 
     WritableBuffer wreg = wbuf.writableRegion();
-    assertEquals(wreg.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
+    assertEquals(wreg.getByteOrder(), ByteOrder.BIG_ENDIAN);
   }
 
   @Test
@@ -251,10 +251,10 @@ public class NonNativeWritableBufferImplTest {
     WritableMemory wmem = WritableMemory.writableWrap(bArr, ByteOrder.BIG_ENDIAN);
     Buffer buf = wmem.asBuffer();
     Buffer dup = buf.duplicate();
-    assertEquals(dup.getTypeByteOrder(), ByteOrder.LITTLE_ENDIAN);
+    assertEquals(dup.getByteOrder(), ByteOrder.LITTLE_ENDIAN);
 
     Buffer reg = buf.region();
-    assertEquals(reg.getTypeByteOrder(), ByteOrder.LITTLE_ENDIAN);
+    assertEquals(reg.getByteOrder(), ByteOrder.LITTLE_ENDIAN);
   }
 
 }
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImplTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImplTest.java
index c6bd5d0..b544e93 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImplTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImplTest.java
@@ -205,7 +205,7 @@ public class NonNativeWritableMemoryImplTest {
   @Test
   public void checkRegion() {
     WritableMemory wreg = wmem.writableRegion(0, wmem.getCapacity());
-    assertEquals(wreg.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
+    assertEquals(wreg.getByteOrder(), ByteOrder.BIG_ENDIAN);
   }
 
   @Test
@@ -213,7 +213,7 @@ public class NonNativeWritableMemoryImplTest {
     byte[] bArr1 = new byte[0];
     WritableMemory wmem1 = WritableMemory.writableWrap(bArr1, ByteOrder.BIG_ENDIAN);
     Memory reg = wmem1.region(0, wmem1.getCapacity());
-    assertEquals(reg.getTypeByteOrder(), ByteOrder.LITTLE_ENDIAN);
+    assertEquals(reg.getByteOrder(), ByteOrder.LITTLE_ENDIAN);
   }
 
 }
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/WritableMemoryTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/WritableMemoryTest.java
index 1226cc5..e21eba8 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/WritableMemoryTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/WritableMemoryTest.java
@@ -38,9 +38,9 @@ public class WritableMemoryTest {
   public void wrapBigEndian() {
     ByteBuffer bb = ByteBuffer.allocate(64); //big endian
     WritableMemory wmem = WritableMemory.writableWrap(bb);
-    assertEquals(wmem.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
+    assertEquals(wmem.getByteOrder(), ByteOrder.BIG_ENDIAN);
     wmem = WritableMemory.writableWrap(bb, ByteOrder.nativeOrder());
-    assertEquals(wmem.getTypeByteOrder(), ByteOrder.LITTLE_ENDIAN);
+    assertEquals(wmem.getByteOrder(), ByteOrder.LITTLE_ENDIAN);
   }
 
   @Test
@@ -54,11 +54,11 @@ public class WritableMemoryTest {
   @Test
   public void allocateWithByteOrder() {
     WritableMemory wmem = WritableMemory.allocate(64, ByteOrder.BIG_ENDIAN);
-    assertEquals(wmem.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
+    assertEquals(wmem.getByteOrder(), ByteOrder.BIG_ENDIAN);
     wmem = WritableMemory.allocate(64, ByteOrder.LITTLE_ENDIAN);
-    assertEquals(wmem.getTypeByteOrder(), ByteOrder.LITTLE_ENDIAN);
+    assertEquals(wmem.getByteOrder(), ByteOrder.LITTLE_ENDIAN);
     wmem = WritableMemory.writableWrap(new byte[64], 32, 32, ByteOrder.BIG_ENDIAN);
-    assertEquals(wmem.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
+    assertEquals(wmem.getByteOrder(), ByteOrder.BIG_ENDIAN);
   }
 
   @Test
@@ -163,11 +163,11 @@ public class WritableMemoryTest {
   @Test
   public void checkWrapWithBO() {
     WritableMemory wmem = WritableMemory.writableWrap(new byte[0], ByteOrder.BIG_ENDIAN);
-    boolean nativeBO = wmem.getTypeByteOrder() == ByteOrder.nativeOrder();
+    boolean nativeBO = wmem.getByteOrder() == ByteOrder.nativeOrder();
     assertFalse(nativeBO);
     println("" + nativeBO);
     wmem = WritableMemory.writableWrap(new byte[8], ByteOrder.BIG_ENDIAN);
-    nativeBO = wmem.getTypeByteOrder() == ByteOrder.nativeOrder();
+    nativeBO = wmem.getByteOrder() == ByteOrder.nativeOrder();
     assertFalse(nativeBO);
     println("" + nativeBO);
   }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org