ztyandjw opened a new issue #2023:
URL: https://github.com/apache/rocketmq/issues/2023


   
   ```
   public SelectMappedBufferResult selectMappedBuffer(int pos) {
           int readPosition = getReadPosition();
           if (pos < readPosition && pos >= 0) {
               if (this.hold()) {
                   ByteBuffer byteBuffer = this.mappedByteBuffer.slice();
                   byteBuffer.position(pos);
                   int size = readPosition - pos;
                   ByteBuffer byteBufferNew = byteBuffer.slice();
                   byteBufferNew.limit(size);
                   return new SelectMappedBufferResult(this.fileFromOffset + 
pos, byteBufferNew, size, this);
               }
           }
   
           return null;
       }
   ```
   
   why need to create the object byteBufferNew
   
   why not 
   
   ```
   public SelectMappedBufferResult selectMappedBuffer(int pos) {
           int readPosition = getReadPosition();
           if (pos < readPosition && pos >= 0) {
               if (this.hold()) {
                   ByteBuffer byteBuffer = this.mappedByteBuffer.slice();
                   byteBuffer.position(pos);
                   int size = readPosition - pos;
                   byteBuffer.limit(size);
                   
   //                ByteBuffer byteBufferNew = byteBuffer.slice();
   //                byteBufferNew.limit(size);
                   return new SelectMappedBufferResult(this.fileFromOffset + 
pos, byteBuffer, size, this);
               }
           }
   ```
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to