public final boolean isSameResource()

in src/main/java/org/apache/datasketches/memory/internal/ResourceImpl.java [460:478]


  public final boolean isSameResource(final Resource that) {
    Objects.requireNonNull(that);
    final MemorySegment thisSeg = this.seg;
    final MemorySegment thatSeg = ((ResourceImpl)that).seg;
    final boolean thisNative = thisSeg.isNative();
    final boolean thatNative = thatSeg.isNative();
    if (thisNative != thatNative) { return false; }
    if (thisNative && thatNative) { //off-heap
      return thisSeg.address() == thatSeg.address()
          && thisSeg.byteSize() == thatSeg.byteSize();
    } else { //on heap
      if (thisSeg.isReadOnly() || thatSeg.isReadOnly()) {
        throw new IllegalArgumentException("Cannot determine 'isSameResource(..)' on heap if either resource is Read-only.");
      }
      return (thisSeg.heapBase().get() == thatSeg.heapBase().get())
          && (thisSeg.address() == thatSeg.address())
          && thisSeg.byteSize() == thatSeg.byteSize();
    }
  }