首页 > 数据库技术 > 详细

netty源码阅读之UnpooledByteBufAllocator

时间:2015-02-27 21:28:45      阅读:774      评论:0      收藏:0      [点我收藏+]

使用IDEA阅读源码Navigate下面的工具是个好东西 。可以帮助分析类的结构等

技术分享

ByteBufAllocator主要用来生成三种ByteBuf :HeadBuffer,DirectBuffer,CompositeBuffer. 还有一个ByteBufAllocator DEFAULT 静态属性。 我们可以通过io.netty.allocator.type来控制该静态属性的类型:unpooled和pooled (是否使用缓冲池)。

 

用于ByteBuf是通过引用计数来管理内存。在AbstractByteBufAllocator引用了一个toLeakAwareBuffer方法帮助分析内存是否泄漏 。具体参考http://blog.csdn.net/damacheng/article/details/42393757

netty根据是否使用缓存池提供了两个实现类。UnpooledByteBufAllocator和PooledByteBufAllocator(这个比较复杂,实现了jemalloc的算法)

 

UnpooledByteBufAllocator根据使用使用sun.misc.Unsafe类提供了两种直接缓存

UnpooledUnsafeDirectByteBuf和UnpooledDirectByteBuf  一个使用unsafe来对直接缓冲区进行操作,一个使用bytebuffer的方法对缓冲区进行操作。

后面看下两种的不同。以便加深对unsafe的认识

netty源码阅读之UnpooledByteBufAllocator

原文:http://www.cnblogs.com/gaoxing/p/4304340.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!