如何實現乙個迴圈緩衝區模型

2021-04-16 07:59:24 字數 1052 閱讀 8353

下面是乙個ringbuffer模型的完整實現,歡迎讀者參考和指正:

typedef  unsigned char  byte;

template

class ringbuffer

~ringbuffer()

ringbuffer(const ringbuffer

& copy) : m_poppos(0)

else

m_pushpos = m_count = copy.m_count;

}ringbuffer& operator=(const ringbuffer

& other)

return (*this);

}

bool is_full() const

bool is_empty() const

size_type size() const

size_type capacity() const

size_type push(const byte *data, size_type length) else

m_count += length;

return (length);

}size_type pop(byte *buf, size_type length) else

m_count -= length;

return (length);

}void clear()

private:

byte                *m_pringbuffer;     // buffer

size_type           m_pushpos;          // 新的push位置:pushpos=

// (poppos+count)% n

size_type           m_poppos;           // 新的pop位置

size_type           m_count;              // 有效位元組數

criticalsection  m_mutex;};

如何實現乙個迴圈緩衝區模型

下面是乙個ringbuffer模型的完整實現,歡迎讀者參考和指正 typedef unsigned char byte template class ringbuffer ringbuffer ringbuffer const ringbuffer copy m poppos 0 else m pu...

如何實現乙個迴圈緩衝區模型

下面是乙個ringbuffer模型的完整實現,歡迎讀者參考和指正 typedef unsigned char byte template class ringbuffer ringbuffer ringbuffer const ringbuffer copy m poppos 0 else m pu...

如何實現乙個迴圈緩衝區模型

下面是乙個ringbuffer模型的完整實現,歡迎讀者參考和指正 typedef unsigned char byte template class ringbuffer ringbuffer ringbuffer const ringbuffer copy m poppos 0 else m pu...