Giter VIP home page Giter VIP logo

bipbuffer's Introduction

Bip-Buffer

Build Status A Rust implementation of Simon Cooke's Bip-Buffer

A Bip-Buffer is similar to a circular buffer, but data is inserted in two revolving regions of the buffer space. This allows reads to return contiguous blocks of memory, even if they span a region that would normally include a wrap-around in a circular buffer. It's especially useful for APIs requiring blocks of contiguous memory, eliminating the need to copy data into an interim buffer before use.

Examples

use bipbuffer::BipBuffer;

// Creates a 4-element Bip-Buffer of u8
let mut buffer: BipBuffer<u8> = BipBuffer::new(4);
{
    // Reserves 4 slots for insert
    let reserved = buffer.reserve(4).unwrap();
    reserved[0] = 7;
    reserved[1] = 22;
    reserved[2] = 218;
    reserved[3] = 56;
}
// Stores the values into an available region,
// clearing the existing reservation
buffer.commit(4);
{
    // Gets the data stored in the region as a contiguous block
    let block = buffer.read().unwrap();
    assert_eq!(block[0], 7);
    assert_eq!(block[1], 22);
    assert_eq!(block[2], 218);
    assert_eq!(block[3], 56);
}
// Marks the first two parts of the block as free
buffer.decommit(2);
{
    // The block should now contain only the last two values
    let block = buffer.read().unwrap();
    assert_eq!(block[0], 218);
    assert_eq!(block[1], 56);
}

bipbuffer's People

Contributors

obmarg avatar squidpickles avatar

Watchers

 avatar  avatar  avatar

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.