netty源码浅析-PooledByteBuf扩容操作

面试官:Netty中的缓冲区为什么比原生NIO更高效 Netty自己的ByteBuf ByteBuf是为了解决ByteBuffer的问题和满足网络应用程序开发人员的日常需求而设计的. JDK中ByteBuffer的缺点: 无法动态扩容长度是固定的,不能动态扩展和收缩,当数据大于ByteBuffer容量时,会发生索引越界异常. API使用复杂读写的时候需要手动调用flip()和rewind()等方法,使用时需要非常谨慎的使用这些api,否则容易出现错误. ByteBuf做了哪些增强? API操作便捷性 动态扩容 多种ByteBuf实现 内.. 阅读详情
PooledByteBuf扩容操作

我们上面分析了分配操作和回收操作,部分代码我们在上面已经分析过了,现在我们看下扩容操作。

final void ensureWritable0(int minWritableBytes) {
        ensureAccessible();
        //如果可以写入的空间比需要写入的空间大直接返回
        if (minWritableBytes <= writableBytes()) {
            return;
        }
        if (checkBounds) {
            //超出了最大可写大小
            if (minWritableBytes > maxCapacity - writerIndex) {
                throw new IndexOutOfBoundsException(String.format(
                        "writerIndex(%d) + minWritableBytes(%d) exceeds maxCapacity(%d): %s",
                        writerIndex, minWritableBytes, maxCapacity, this));
            }
        }
     //计算扩容后的值
        int newCapacity = alloc().calculateNewCapacity(writerIndex + minWritableBytes, maxCapacity);

        // 扩容
        capacity(newCapacity);
    }

在AbstractByteBuf中会有很多调用ensureWritable0的操作,判断需不需要扩容,我们跟踪到这个方法中,如果需要写入的空间比可写内存小则直接返回,不需要扩容,如果不是则重新计算需要扩容的长度

public int calculateNewCapacity(int minNewCapacity, int maxCapacity) {
        checkPositiveOrZero(minNewCapacity, "minNewCapacity");
     //扩容长度不能超过最大值
        if (minNewCapacity > maxCapacity) {
            throw new IllegalArgumentException(String.format(
                    "minNewCapacity: %d (expected: not greater than maxCapacity(%d)",
                    minNewCapacity, maxCapacity));
        }
        final int threshold = CALCULATE_THRESHOLD; // 4 MiB page

        if (minNewCapacity == threshold) {
            return threshold;
        }

        if (minNewCapacity > threshold) {//如果大于4M
            int newCapacity = minNewCapacity / threshold * threshold;//向上取整
            if (newCapacity > maxCapacity - threshold) {
                newCapacity = maxCapacity;
            } else {
                newCapacity += threshold;
            }
            return newCapacity;
        }

        //如果没有达到4M,则以64B开始每次翻一倍扩展
        int newCapacity = 64;
        while (newCapacity < minNewCapacity) {
            newCapacity <<= 1;
        }

        return Math.min(newCapacity, maxCapacity);
    }

这里会先判断需要扩容的大小不能超过最大值,如果大小超过了4M,则每次向上取整获取扩容的大小,如果小于4M,则以64开始每次翻一倍,获取大于minNewCapacity的扩容值。我们继续跟踪

public final ByteBuf capacity(int newCapacity) {
        checkNewCapacity(newCapacity);

        // If the request capacity does not require reallocation, just update the length of the memory.
        //如果不是池化的
        //如果请求容量不需要重新分配,则只需更新内存的长度即可
        if (chunk.unpooled) {
            if (newCapacity == length) {
                return this;
            }
        } else {
            //如果需要分配长度大于已经分配的长度,但是不大于最大可分配的长度,直接返回
            if (newCapacity > length) {
                if (newCapacity <= maxLength) {
                    length = newCapacity;
                    return this;
                }
            } else if (newCapacity < length) {
                //如果新的长度小于length
                if (newCapacity > maxLength >>> 1) {
                    if (maxLength <= 512) {//tiny类型
                        if (newCapacity > maxLength - 16) {
                            length = newCapacity;
                            //重新设置读写索引
                            setIndex(Math.min(readerIndex(), newCapacity), Math.min(writerIndex(), newCapacity));
                            return this;
                        }
                    } else { // > 512 (i.e. >= 1024)
                        length = newCapacity;
                        //重新设置读写索引
                        setIndex(Math.min(readerIndex(), newCapacity), Math.min(writerIndex(), newCapacity));
                        return this;
                    }
                }
            } else {
                return this;
            }
        }

        // Reallocation required.
        //需要重新分配
        chunk.arena.reallocate(this, newCapacity, true);
        return this;
    }

这里会根据不同情况判断需要不需要扩容,如果需要扩容则执行reallocate方法

void reallocate(PooledByteBuf<T> buf, int newCapacity, boolean freeOldMemory) {
        if (newCapacity < 0 || newCapacity > buf.maxCapacity()) {
            throw new IllegalArgumentException("newCapacity: " + newCapacity);
        }

        int oldCapacity = buf.length;
        if (oldCapacity == newCapacity) {
            return;
        }

        PoolChunk<T> oldChunk = buf.chunk;
        ByteBuffer oldNioBuffer = buf.tmpNioBuf;
        long oldHandle = buf.handle;
        T oldMemory = buf.memory;
        int oldOffset = buf.offset;
        int oldMaxLength = buf.maxLength;
        int readerIndex = buf.readerIndex();
        int writerIndex = buf.writerIndex();
        //重新申请newCapacity大小内存
        allocate(parent.threadCache(), buf, newCapacity);
        if (newCapacity > oldCapacity) {
            memoryCopy(
                    oldMemory, oldOffset,
                    buf.memory, buf.offset, oldCapacity);
        } else if (newCapacity < oldCapacity) {
            //设置写索引
            if (readerIndex < newCapacity) {
                if (writerIndex > newCapacity) {
                    writerIndex = newCapacity;
                }
                //内存赋值
                memoryCopy(
                        oldMemory, oldOffset + readerIndex,
                        buf.memory, buf.offset + readerIndex, writerIndex - readerIndex);
            } else {
                readerIndex = writerIndex = newCapacity;
            }
        }
        //设置读写索引
        buf.setIndex(readerIndex, writerIndex);
        //释放原来的分配的内存
        if (freeOldMemory) {
            free(oldChunk, oldNioBuffer, oldHandle, oldMaxLength, buf.cache);
        }
    }

这里很多方法我们在上面已经分析过了,这里就不再详细分析

Netty ByteBuf源码解析:内存模型、池化分配与泄漏排查实战 在Java网络编程中,高效的数据容器是保障高性能通信的基础。ByteBuf作为Netty的核心组件,通过读写索引分离、引用计数与池化分配等机制,解决了传统ByteBuffer在易用性、扩容和内存回收方面的痛点。其底层支持堆内、直接内存及Unsafe等多种实现,结合零拷贝特性,可显著降低IO路径上的数据复制开销。在复杂业务场景下,正确的资源释放与内存复用策略尤为关键,而Netty的资源泄漏检测器能够帮助开发者快速定位问题。本文从内存模型、源码实现、分配器原理到线上排查实践,系统梳理了ByteBuf的完整知识链 阅读详情

相关推荐

驱动钛丝(SMA)的应用(5)汽车腰托气阀常见问题及解决方案

财哥在前段时间发布的《驱动钛丝(SMA)的应用(1)汽车腰托支撑按摩气阀模块》一文,引发了很多企业的拜访和交流。 目前很多厂家已经启动或正在进行相关研发,同时也遇到了诸如:钛丝选型、驱动位移、响应设计、温度控制、力量设计、点动滞后、铆接工艺、量化生产等问题。

weixin_39168671的博客 1239

Netty源码阅读之ByteBuf简析(二)

前面对于Netty中的ByteBuf缓存做了一下简单的介绍,下面将围绕源码,对于其中的几个特性进行分析。 1.扩容机制 首先来聊下Bytebuf的扩容机制,这个机制也是Netty比较强悍的地方,而我们知道JDK自带的ByteBuffer是无法扩容的,在Bytebuf创建的时候,我们通常会设置一个初始容量,在我们写数据的时候,如果写指针超过了设置的初始容量,那么Bytebuf将进行扩容,废话不多说,下面我们直接通过源码来一探究竟吧: public ByteBuf writeBytes(ByteBuf

记忆碎片 1027

告别地图偏移!手把手教你用MapOnline V1.2在ArcGIS里加载无偏谷歌影像和历史影像

本文详细介绍了如何使用MapOnline V1.2插件在ArcGIS中加载无偏谷歌影像和历史影像,解决GIS工程师长期面临的地图偏移问题。通过三步安装配置、无偏影像加载和时空分析功能,提升地理信息数据的精确度和工作效率,特别适用于城市规划、环境监测等场景。

weixin_29252171的博客 232

ByteBuf的扩容机制

Netty 的ByteBuf扩容机制通过不同的实现类和方法,提供了灵活且高效的内存管理方案。在实际使用中,可以根据具体的需求选择合适的ByteBuf实现类和扩容策略,以提高系统的性能和稳定性。同时,了解扩容机制有助于更好地使用ByteBuf,避免不必要的内存开销和性能问题。

eclipseC的博客 624

华为AR6140E/S5735设备密码策略配置全攻略:从复杂度到锁定机制

本文详细介绍了华为AR6140E/S5735设备的密码策略配置方法,涵盖密码复杂度、时效性和防护性三大核心维度。通过具体的CLI命令示例,指导管理员如何设置密码长度、字符组合、有效期及登录失败锁定等安全机制,为企业网络提供全面的用户名密码防护策略。

weixin_30836759的博客 530

LIN协议V2.2A版介绍

IN 协议规范2.2A 版(2010 年 12 月发布)是面向低成本汽车网络的标准,核心采用单主多从架构,支持最高20kbit/s速率,通过单总线实现通信;定义了完整的协议栈(含协议层、传输层、物理层等),规定了帧结构(含 Break 字段、Sync 字节、保护标识符 PID、数据字段、校验和)、5 类帧类型(无条件帧、事件触发帧等)及调度表机制以保障确定性传输;

qflook的博客 319

Netty源码分析-AbstractByteBuf

public abstract class AbstractByteBuf extends ByteBuf { private static final InternalLogger logger = InternalLoggerFactory.getInstance(AbstractByteBuf.class); private static final String ...

大新博客 563

基于FPGA的以太网设计(1)----大白话解释什么是以太网

基于FPGA的千兆以太网设计(1)----大白话解释什么是以太网

孤独的单刀 3869

UnpooledHeadByteBuf源码分析

1.简单介绍1.UnpooledHeadByteBuf简介 UploadedHeadByteBuf是基于堆内存进行内存分配的字节缓存区,他没有基于对象池的技术实现,意味着每次io的读写都会创建一个新的UnpooledHeadByteBuf,频繁进行大块内存的分配和回收对性能会造成一定的影响,但是相比于堆外内存的申请和释放,他的成本低一点。相比于PooledHeadbyteBuf

heihei 1036

基于FPGA的UDP 通信(一)

手头的FPGA开发板上有一个千兆网口,最近准备做一下以太网通信的内容。本文先介绍基本的理论知识。 FPGA芯片型号:xc7a35tfgg484-2 网口芯片:RTL8211 网络接口:RJ45

记录所学,分享知识,结识挚友 8357

C#操作MySQL从入门到精通(1)——安装MySQL数据库

我们使用C#操作MySQL数据库第一步要做的就是安装MySQL数据库,本文就是详细讲解如何安装MySQL数据库。

qq_34059233的博客 962

《Netty》从零开始学netty源码(四十六)之PooledByteBuf

《Netty》从零开始学netty源码(四十六)之PooledByteBuf

Lanna_w的博客 1374

从零开始学Agent的搭建——多角色项目需求分析框架实战

场景一:电商促销需求——技术细节顾此失彼团队用单Agent分析一个"双11秒杀系统"的需求。Agent输出了完整的功能清单,但当我们拿着这份方案找架构师评审时,发现了致命问题:Agent完全没有考虑库存扣减的并发一致性、Redis与MySQL之间的数据同步延迟、以及超卖风险的控制策略。原因是单Agent在处理"业务理解"任务时,已经耗尽了它的"注意力预算",技术深度分析几乎为空。场景二:ERP集成需求——跨系统边界模糊。

软件行业技术文化交流。 533

《Netty》从零开始学netty源码(四十七)之PooledByteBuf的方法

《Netty》从零开始学netty源码(四十七)之PooledByteBuf的方法

Lanna_w的博客 1038

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Netty学习之旅----源码分析内存分配与释放原理

互联网大厂比较喜欢的人才特点:对技术有热情,强硬的技术基础实力;主动,善于团队协作,善于总结思考。无论是哪家公司,都很重视高并发高可用技术,重视基础,所以千万别小看任何知识。面试是一个双向选择的过程,不要抱着畏惧的心态去面试,不利于自己的发挥。同时看中的应该不止薪资,还要看你是不是真的喜欢这家公司,是不是能真的得到锻炼。其实我写了这么多,只是我自己的总结,并不一定适用于所有人,相信经过一些面试,大家都会有这些感触。下面有部分截图希望能对大家有所帮助。

2401_84092574的博客 942

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

【Netty源码】ByteBuf源码剖析

ByteBuf概述1.ByteBuf与ByteBuffer的区别 ByteBuf不是对ByteBuffer的封装,而是重新实现了一个缓冲区。ByteBuffer只使用了一个position指针来记录当前的读写位置,ByteBuf使用了两个指针readerIndex, writerIndex分别来记录当前的读写位置,使用起来更加简单和方便。 ByteBuffer是一个固定长度的缓冲区,当put方法要写

白夜行 963

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Netty篇:ByteBuf部分源码分析

缓冲区(Buffer)      缓冲区(Buffer)就是在内存中预留指定大小的存储空间用来对输入/输出(I/O)的数据作临时存储,这部分预留的内存空间就叫做缓冲区:      使用缓冲区可以减少实际的物理读写次数,而且缓冲区在创建时就被分配内存,这块内存区域一直被重用,可以减少动态分配和回收...

走在路上 381

Netty零拷贝机制

Netty零拷贝机制Netty自己的ByteBufJDK ByteBuffer的缺点:ByteBuf做了那些增强ByteBuf操作 Netty自己的ByteBuf ByteBuf是为解决ByteBuffer的问题和满足网络应用程序开发人员的日常需求儿设计的。 JDK ByteBuffer的缺点: 1、无法动态扩容      长度是固定的,不能动态扩...

weixin_45489092的博客 495

Netty 权威指南笔记(五):ByteBuf 源码解读

Java 本身提供了 ByteBuffer 类,为什么 Netty 还要搞一个 ByteBuf 类呢?因为 ByteBuffer 类有着许多缺点: 1. ByteBuffer 长度固定,无法动态伸缩。 2. ByteBuffer 只有一个位置指针 position,读写的时候需要手工调用 flip 和 rewind 方法进行模式转换,操作繁琐,容易出错。 3. 功能太少,缺少一些高级特性。

albon arith 1815

Netty5源码分析(五) -- ByteBuf缓冲区

Netty的ByteBuf缓冲区实现地比Java本身的ByteBuffer更加灵活,方便。它的类结构也比较复杂,这里只说ByteBuf核心的几个要点。 1. 最重要的是要理解为什么要ByteBuf这个组件。主要还是因为基于select / poll / epoll这种IO多路复用技术的NIO是非阻塞同步IO的模型,由于是同步IO,需要用户线程自己来处理IO的读写,由于是非阻塞的,每次调用

ITer_ZC的专栏 5749

Netty学习之旅----源码分析内存分配与释放原理,java基础面试集合

subpage = new PoolSubpage(this, id, runOffset(id), pageSize, normCapacity); // 代码@3 subpages[subpageIdx] = subpage; } else { //@4 subpage.init(normCapacity); } return subpage.allocate(); //代码@5 } 首先讲解一下整体分配思路,先根据PoolChunk内部维护的各个PoolChunk的占用情况,返回一个可以PoolChu

m0_63176399的博客 565

Netty ByteBuf源码分析

Netty的ByteBuf是JDK中ByteBuffer的升级版,提供了NIO buffer和byte数组的抽象视图。 ByteBuf的主要类集成关系: (图片来自Netty权威指南,图中有一个画错的地方是PooledByteBuf中的最后一个子类应该是PooledUnsafeDirectByteBuf) 从继承关系可以看出AbstractReferenceCountedByte...

weixin_33851177的博客 147

bytebuf池_Netty ByteBuf源码分析

Netty的ByteBuf是JDK中ByteBuffer的升级版,提供了NIO buffer和byte数组的抽象视图。ByteBuf的主要类集成关系:(图片来自Netty权威指南,图中有一个画错的地方是PooledByteBuf中的最后一个子类应该是PooledUnsafeDirectByteBuf)从继承关系可以看出AbstractReferenceCountedByteBuf的子类分为两类:P...

weixin_39724793的博客 117
上一篇: netty源码浅析-池化内存回收
下一篇: netty源码浅析-池化内存PoolThreadCache分配
胖柯G
博客等级 码龄10年 453粉丝 57原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值