Openrtmfp/Cumulus primer (13) local memory chip for Io Management

Source: Internet
Author: User


Openrtmfp/Cumulus primer (13) local memory chip for Io Management

  • Author: Liu Da-poechant (Zhong Chao)
  • Email: zhongchao. USTC # gmail.com (#-> @)
  • Blog: blog.csdn.net/poechant
  • Date: 10000l 24Th, 2012

First, this class is not used in openrtmfp/Cumulus, so you can close the current tab of your browser to avoid wasting time.

In the memorystreambuf introduced in "openrtmfp/Cumulus primer (10) stream buffer for Io Management", there is a friend named scopedmemoryclip, which is what this article will introduce

First, the most important thing is that scopedmemoryclip has a memorystreambuf member.

class ScopedMemoryClip {public:    ScopedMemoryClip(MemoryStreamBuf& buffer,Poco::UInt32 offset);    ~ScopedMemoryClip();private:    void                clip(Poco::Int32 offset);    Poco::UInt32        _offset;    MemoryStreamBuf&   _buffer;};
1 Constructor

The parameters passed in by the constructor correspond to the two member values of scopedmemoryclip. The offset cannot exceed the online value of the memorystremambuf buffer.

ScopedMemoryClip::ScopedMemoryClip(MemoryStreamBuf& buffer, UInt32 offset)    : _offset(offset), _buffer(buffer) {    if (_offset >= _buffer._bufferSize)        _offset = _buffer._bufferSize - 1;    if (_offset < 0)        _offset = 0;    clip(_offset);}
2 destructor
ScopedMemoryClip::~ScopedMemoryClip() {    clip(-(Int32)_offset);}
3 buffer Cutting

We can see that both the constructor and the Destructor call the clip function. This function completes the buffer and forms a local memory chip:

  • If the input offset parameter is positive, only the last part after the cut is retained.
  • If the input parameter is negative, it is equivalent to expanding the buffer area forward. (Only occurs in destructor)

The source code is as follows.

Void scopedmemoryclip: Clip (int32 offset) {// obtain gptr char * gpos = _ buffer. gcurrent (); // offset the buffer address and modify the buffer size _ buffer. _ pbuffer + = offset; _ buffer. _ buffersize-= offset; // The Position of the pptr minus the new address of the buffer, which is used as the new position of the pptr int PPOs = _ buffer. pcurrent ()-_ buffer. _ pbuffer; // set the gptr reachable zone and location _ buffer. setg (_ buffer. _ pbuffer, gpos, _ buffer. _ pbuffer + _ buffer. _ buffersize); // set the reachable regions and locations of pptr _ buffer. setp (_ buffer. _ pbuffer, _ buffer. _ pbuffer + _ buffer. _ buffersize); _ buffer. pbump (PPOs); // if the number of written data is smaller than the offset, you can set the number of written data to zero if (_ buffer. _ written <OFFSET) _ buffer. _ written = 0; // if the number of written data is greater than or equal to the offset, offset else _ buffer is subtracted. _ written-= offset; // if the number of written nodes is greater than the buffer capacity, it is set to the buffer capacity if (_ buffer. _ written> _ buffer. _ buffersize) _ buffer. _ written = _ buffer. _ buffersize ;}

-

Reprinted, please indicate the csdn blog from LIU Da: blog.csdn.net/poechant

-

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.