From 4e9e465360b2b4757699e79b265c12358ac5e8db Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 4 Aug 2020 02:00:00 +0200 Subject: [PATCH] shared ring buffer continued --- container/SimpleRingBuffer.cpp | 20 ++++++++++++++++---- container/SimpleRingBuffer.h | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/container/SimpleRingBuffer.cpp b/container/SimpleRingBuffer.cpp index 3cc1ffdf..cad1a48e 100644 --- a/container/SimpleRingBuffer.cpp +++ b/container/SimpleRingBuffer.cpp @@ -2,16 +2,28 @@ #include SimpleRingBuffer::SimpleRingBuffer(const size_t size, bool overwriteOld, - size_t maxExcessBytes) : + size_t maxExcessBytes) : RingBufferBase<>(0, size, overwriteOld), maxExcessBytes(maxExcessBytes) { + if(maxExcessBytes > size) { + this->maxExcessBytes = size; + } + else { + this->maxExcessBytes = maxExcessBytes; + } buffer = new uint8_t[size + maxExcessBytes]; } SimpleRingBuffer::SimpleRingBuffer(uint8_t *buffer, const size_t size, - bool overwriteOld, size_t maxExcessBytes): - RingBufferBase<>(0, size, overwriteOld), buffer(buffer), - maxExcessBytes(maxExcessBytes) {} + bool overwriteOld, size_t maxExcessBytes): + RingBufferBase<>(0, size, overwriteOld), buffer(buffer) { + if(maxExcessBytes > size) { + this->maxExcessBytes = size; + } + else { + this->maxExcessBytes = maxExcessBytes; + } +} SimpleRingBuffer::~SimpleRingBuffer() { diff --git a/container/SimpleRingBuffer.h b/container/SimpleRingBuffer.h index 4bb3a4e8..2627541f 100644 --- a/container/SimpleRingBuffer.h +++ b/container/SimpleRingBuffer.h @@ -111,7 +111,7 @@ public: private: static const uint8_t READ_PTR = 0; uint8_t* buffer = nullptr; - const size_t maxExcessBytes; + size_t maxExcessBytes; size_t excessBytes = 0; };