Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问一下,对于ByteBuffer makeSpace函数会经常把数据往前移动,也就是说拷贝,这个会比较费吗? #52

Open
asynchronoust opened this issue Jul 11, 2021 · 0 comments

Comments

@asynchronoust
Copy link

asynchronoust commented Jul 11, 2021

image

上图中的

 void makeSpace(size_t len)
        {
            //kCheapPrepend为保留的空间
            if (writableBytes() + prependableBytes() < len + kCheapPrepend)
            {
                // FIXME: move readable data
                m_buffer.resize(m_writerIndex + len);
            }
            else
            {
                // move readable data to the front, make space inside buffer
                //assert(kCheapPrepend < readerIndex_);
                if (kCheapPrepend >= m_readerIndex)
                    return;

                size_t readable = readableBytes();
                std::copy(begin() + m_readerIndex,
                    begin() + m_writerIndex,
                    begin() + kCheapPrepend);
                m_readerIndex = kCheapPrepend;
                m_writerIndex = m_readerIndex + readable;
            }
        }

应该在收包的过程中,这种copy数据应该是很常发生的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant