You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2020/05/21 09:25:27 UTC

[GitHub] [rocketmq] ztyandjw opened a new issue #2023: MappedFile#selectMappedBuffer(int pos)

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:
users@infra.apache.org



[GitHub] [rocketmq] RongtongJin closed issue #2023: no use to create byteBufferNew in function MappedFile#selectMappedBuffer(int pos)

Posted by GitBox <gi...@apache.org>.
RongtongJin closed issue #2023:
URL: https://github.com/apache/rocketmq/issues/2023


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [rocketmq] RongtongJin commented on issue #2023: no use to create byteBufferNew in function MappedFile#selectMappedBuffer(int pos)

Posted by GitBox <gi...@apache.org>.
RongtongJin commented on issue #2023:
URL: https://github.com/apache/rocketmq/issues/2023#issuecomment-632604247


   I think it is necessary to create. Although byteBuffer and byteBufferNew share the same content, the values of position, limit, and mark are independent. For example, byteBuffer current position is pos, byteBufferNew is 0. 


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [rocketmq] ztyandjw commented on issue #2023: no use to create byteBufferNew in function MappedFile#selectMappedBuffer(int pos)

Posted by GitBox <gi...@apache.org>.
ztyandjw commented on issue #2023:
URL: https://github.com/apache/rocketmq/issues/2023#issuecomment-632610680


   > I think it is necessary to create. Although byteBuffer and byteBufferNew share the same content, the values of position, limit, and mark are independent. For example, byteBuffer current position is pos, byteBufferNew is 0.
   
   ok, i find the new  bytebuffer used  in function checkMessageAndReturnSize, use it's position from 0... 
   thanyou~


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [rocketmq] ztyandjw removed a comment on issue #2023: no use to create byteBufferNew in function MappedFile#selectMappedBuffer(int pos)

Posted by GitBox <gi...@apache.org>.
ztyandjw removed a comment on issue #2023:
URL: https://github.com/apache/rocketmq/issues/2023#issuecomment-632610680


   > I think it is necessary to create. Although byteBuffer and byteBufferNew share the same content, the values of position, limit, and mark are independent. For example, byteBuffer current position is pos, byteBufferNew is 0.
   
   ok, i find the new  bytebuffer used  in function checkMessageAndReturnSize, use it's position from 0... 
   thanyou~


----------------------------------------------------------------
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:
users@infra.apache.org