Skip to content

Conversation

BOND12
Copy link

@BOND12 BOND12 commented Jan 17, 2023

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

If the skip method has to skip positions for reading more than written to the buffer, the buffer operation breaks, because read_position becomes larger than write_position.
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

Successfully merging this pull request may close these issues.

1 participant