in src/main/java/org/apache/datasketches/memory/internal/WritableBufferImpl.java [173:193]
private WritableBuffer duplicateImpl(final boolean localReadOnly, final ByteOrder byteOrder) {
if (!this.isAlive()) { throw new IllegalStateException("This Memory is not alive."); }
final boolean readOnly = isReadOnly() || localReadOnly;
final MemorySegment seg2 = (readOnly && !seg.isReadOnly()) ? seg.asReadOnly() : seg;
final boolean regionType = isRegion();
final boolean mapType = seg.isMapped();
final boolean directType = seg.isNative();
final boolean nativeBOType = byteOrder == ByteOrder.nativeOrder();
final boolean byteBufferType = hasByteBuffer();
final int type = BUFFER | DUPLICATE
| (readOnly ? READONLY : 0)
| (regionType ? REGION : 0)
| (mapType ? MAP : 0)
| (directType ? DIRECT : 0)
| (nativeBOType ? NATIVE_BO : NONNATIVE_BO)
| (byteBufferType ? BYTEBUF : 0);
final WritableBuffer wbuf = selectBuffer(seg2, type, memReqSvr, byteBufferType, mapType, nativeBOType);
wbuf.setStartPositionEnd(getStart(), getPosition(), getEnd());
return wbuf;
}