You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2018/01/18 14:57:13 UTC

[GitHub] merlimat commented on issue #1078: Re-implement DoubleByteBuf as a simple holder of a pair of buffers

merlimat commented on issue #1078: Re-implement DoubleByteBuf as a simple holder of a pair of buffers
URL: https://github.com/apache/incubator-pulsar/pull/1078#issuecomment-358671127
 
 
   > the only thing I'm concerned with is reference counting, we're not retaining the buffers when we get a ByteBufPair but we're releasing them when we release the pair,
   
   This is similar to the previous behavior, just a bit simplified. The main goal is that creating a ByteBufPair and writing it to the channel:
   
   ```java
   ByteBuf b = ... 
   // b.refCnt() == 1
   ctx.writeAndFlush(b); 
   // When write is completed the object is automatically 
   // released and  buffer is returned to pool
   ```
   
   With ByteBufPair it will be the same: 
   
   ```java
   ByteBuf b1, b2;
   // b1.refCnt() == 1
   // b2.refCnt() == 1
   
   ByteBufPair p = ByteBufPair.get(b1, b2);
   // Still
   // b1.refCnt() == 1
   // b2.refCnt() == 1
   // b.refCnt() == 1
   
   ctx.writeAndFlush(b);
   
   // When writing, b1 and b2 get also incremented before the write 
   // to compensate the intrinsic release
   ```
   
   At the end, `b` gets released and deallocated, which will trigger the release of `b1` and `b2`.
   
   Bottom line, when doing `ByteBufPair.get(b1, b2)` the current ownership (of 1 ref-count) for both `b1` and `b2` is transferred to the `ByteBufPair` instance. This is same behavior as previously with the `DoubleByteBuf`. The only difference is that previously we were doing `retain()` and `realease(2)`, but that doesn't change the counter math. 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


With regards,
Apache Git Services