/circular

A lock free circular buffer in Go

Primary LanguageGoApache License 2.0Apache-2.0

Circular Buffer

A lock free circular buffer in Go

Build Status GoDoc

This package is written to be a lock free circular buffer. It stores the items as unsafe.Pointer objects. Usage is quite simple...

How to download

go get -u github.com/levigross/circular

Usage

import "github.com/levigross/circular"


// This creates a buffer that is 100 elements large 
myBuffer := circular.Buffer(100)

for i := 0; i != 100; i++ {
		myInt := i // copy the int because we are storing unsafe.Pointers
		myBuf.Push(unsafe.Pointer(&myInt))
}

// Getting an item requires you to cast the object from an unsafe.Pointer
myint := *(*int)(myBuf.Pop())