Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add template parameter to make it a overwriting ring buffer #9

Open
jrahlf opened this issue Nov 21, 2020 · 1 comment
Open

Add template parameter to make it a overwriting ring buffer #9

jrahlf opened this issue Nov 21, 2020 · 1 comment

Comments

@jrahlf
Copy link

jrahlf commented Nov 21, 2020

Hi,

how about adding a template parameter which makes it an overwriting ring buffer?
I.e. when buffer is full, calling insert() replaces the oldest value with the new value. Then the tail also has to be updated, which means the ring buffer cannot be lock free anymore.

I really like your implementation and this addition would make it even more generalized.

@jnk0le
Copy link
Owner

jnk0le commented Dec 9, 2020

Overwiriting insert is wanted function especially in atomic context. Probably as separate function instead of overloading. I'll definitely add it in mpmc, but non atomic overloads of insert is going to be a lot of burden now.

It is still possible to inherit from the spsc class and add followinfg function

//non atomic, returns true if overwritten
bool insertOverwrite(T data)
{
	if(!insert(data)) {
		remove();
		insert(data);
		return true;
	}
	return false;
}

not the most efficient, but should work.

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

No branches or pull requests

2 participants