EmbeddedRingBuffer icon indicating copy to clipboard operation
EmbeddedRingBuffer copied to clipboard

Fixed some bugs

Open BOND12 opened this issue 3 years ago • 0 comments

In the original version , the code:

#include <iostream>
using namespace std;

#include "RingBuffer.h"

RingBuffer<10, int> rb;

int main() {
	for (int i = 0; i < 8; ++i) {
		rb.Append(i);
	}

	while (rb.Available()) {
		cout << rb.Read(1).At(0) << endl;
		//rb.Skip(1);
	}



	return 0;
}

falls into an infinite loop, because the Read method does not move the buffer read pointer to the next position. This can be done using the Skip method, of course, but I think it's not right. I fixed it. I also fixed the Skip method itself, because in the original version it did not control the input parameter to see if it could be more than the available amount of data to read. I corrected that too

BOND12 avatar Jan 17 '23 19:01 BOND12