# Circular buffer package?

**URL:** https://discourse.julialang.org/t/circular-buffer-package/44041
**Category:** General Usage
**Created:** [July 31, 2020, 3:02pm UTC](https://discourse.julialang.org/t/circular-buffer-package/44041 "2020-07-31T15:02:10Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![lwabeke](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lwabeke/32/4005_2.png) [@lwabeke](https://discourse.julialang.org/u/lwabeke)
#### Post date: [July 31, 2020, 3:02pm UTC](https://discourse.julialang.org/t/circular-buffer-package/44041/1 "2020-07-31T15:02:10Z")

</div>

I am working on some code that processes vectors of data of length 6000 elements. When I detect specific criteria, I want to reprocess the last 100 vectors to extract finer details. Thus I want to store the data in a form of a FIFO “cache”, replacing the oldest data as I go.

I am thinking of using a circular buffer, but I’m not seeing a package that directly support it.

I see there is Ringbuffers.jl which wraps a C library. I don’t specifically want to use it as a FIFO with variable amount of data and thus the reading will not be simple pop in sequence (for example might need to fetch some of the data twice if 2 events are detected within 100 vectors of each other, thus I’m not sure if the read interfacing supported with Ringbuffers.jl will be limiting for my use case.

I also see FFTViews.jl which seems to implement a periodic indexing but come with a number of warnings about using it away from FFT.

My guess is either of them can be made to work, or creating a custom implementation might also not be too difficult.

Any thoughts or suggestions?  
Thanks

---

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [July 31, 2020, 3:46pm UTC](https://discourse.julialang.org/t/circular-buffer-package/44041/2 "2020-07-31T15:46:31Z")

</div>

[https://juliacollections.github.io/DataStructures.jl/latest/circ\_buffer/](https://juliacollections.github.io/DataStructures.jl/latest/circ_buffer/)

---

<div class="post-metadata">

### Author: ![lwabeke](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lwabeke/32/4005_2.png) [@lwabeke](https://discourse.julialang.org/u/lwabeke)
#### Post date: [August 5, 2020, 12:10pm UTC](https://discourse.julialang.org/t/circular-buffer-package/44041/3 "2020-08-05T12:10:47Z")

</div>

Thanks

I believe my use case will benefit from being able to use negative indexing, similar to [https://github.com/JuliaCollections/DataStructures.jl/pull/451](https://github.com/JuliaCollections/DataStructures.jl/pull/451)

I see the CircularBuffer is a vector.

I was inspired by the idea in [https://github.com/JuliaCollections/DataStructures.jl/pull/445/files](https://github.com/JuliaCollections/DataStructures.jl/pull/445/files) where CircularVectorBuffer is defined to create a 2d-Array and I decided to utilize a custom N+1-dimensional array with limited functionality, although I suspect a CircularBuffer{Any} with elements Array{T,N} would have worked just as well for my use case.

---

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [August 5, 2020, 12:45pm UTC](https://discourse.julialang.org/t/circular-buffer-package/44041/4 "2020-08-05T12:45:08Z")

</div>

what about CircularArrays.jl
