Giter Club home page Giter Club logo

rbuf's Introduction

rbuf: a circular ring buffer in Golang

type FixedSizeRingBuf struct:

  • is a fixed-size circular ring buffer. Yes, just what is says. This structure is only for bytes, as it was written to optimize I/O, but could be easily adapted to any other type.

  • We keep a pair of ping/pong buffers so that we can linearize the circular buffer into a contiguous slice if need be.

For efficiency, a FixedSizeRingBuf may be vastly preferred to a bytes.Buffer. The ReadWithoutAdvance(), Advance(), and Adopt() methods are all non-standard methods written for speed.

For an I/O heavy application, I have replaced bytes.Buffer with FixedSizeRingBuf and seen memory consumption go from 8GB to 25MB. Yes, that is a 300x reduction in memory footprint. Everything ran faster too.

Note that Bytes(), while inescapable at times, is expensive: avoid it if possible. If all you need is len(Bytes()), then it is better to use the FixedSizeRingBuf.Readable member directly. Bytes() is expensive because it may copy the back and then the front of a wrapped buffer A[Use] into A[1-Use] in order to get a contiguous, unwrapped, slice. If possible use ContigLen() first to get the size that can be read without copying, Read() that amount, and then Read() a second time -- to avoid the copy.

copyright (c) 2014, Jason E. Aten

license: MIT

rbuf's People

Contributors

codelingobot avatar glycerine avatar nicolov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rbuf's Issues

Write even if there is no capacity.

In my usage, I need have to write to the ring buffer, when there is no space, just auto advance some space.

Can I make a pr for the function WriteWithAdvance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.