MyNixOS website logo
Description

Circular / Ring Buffers.

Circular / ring buffers in R and C. There are a couple of different buffers here with different implementations that represent different trade-offs.

ring

Project Status: Active - The project has reached a stable, usable state and is being actively developed. R-CMD-check codecov.io

Ring buffers in R and C

Ring buffers (or circular buffers) are like arrays that seem circular; data is written and read in a first-in-first-out (FIFO) style, but once allocated subsequent writes do not cause memory allocations. Circular buffers are useful for collecting and processing data streams or for queues (with a fixed maximum size). I use them to implement a solver for delay differential equations in dde.

This package provides two implementations of ring buffers:

  1. ring_buffer_env: a pure R ring buffer implemented as double linked list (using environments) that is genuinely a ring.
  2. ring_buffer_bytes: a ring buffer implemented as an array of bytes with a pair of pointers (in C). Each "element" of the array can be one or more bytes, but each must have a fixed size. There are two convenience interfaces:
  • ring_buffer_bytes_translate: for cases where a raw->R and R->raw translation functions are provided
  • ring_buffer_bytes_typed for cases where each element should correspond to a fixed-length vector of one of R's core numeric-ish types (logical, integer, numeric, complex)

Both buffer types can be used from R, and the code underlying ring_buffer_bytes can also be used compiled code in other packages using R's LinkingTo: support. A common set of methods is provided, though these do differ in some details.

Both buffer types will refuse to underflow (return elements beyond those that have been written). The behaviour on overflow can be controlled:

  • overwrite old data: (the default), for a fixed-memory FIFO buffer
  • grow buffer: expand the buffer geometrically to fit required elements (which will require additional memory allocations and copies)
  • throw error: refuse to overflow

Depending on your application, these ring buffers may or may not be faster than manually copying data around in vectors. The benefit of this package rather than doing it by hand is abstracting away a lot of subtle bookkeeping and keeping an interface that is fairly high level. However, for C applications, using ring_buffer_bytes via the C interface (using LinkingTo) is likely to be very fast as it avoids all copies.

See the reference documentation for details.

Usage

The main package vignette (vignette("ring")) contains an introduction and basic usage.

A second vignette (vignette("ring_applications")) describes possible data structures using a ring buffer.

The reference documentation is also available online, or from the package.

License

MIT © Imperial College of Science, Technology and Medicine

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Metadata

Version

1.0.5

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows