Skip to main content

A circular/ring buffer written in C

Project description

A python extension implementing a circular/ring buffer of characters as a C extension. It overwrites silently.


Currently, pyringbuf is available at, or via pip install pyringbuf. As this is a C extension, there is a compilation step, so your system will need to be able to compile extension modules for python.


>>> from ringbuf import RingBuffer
>>> R = RingBuffer(5)    #choose your buffer size
>>> R.push("a")          #push a single character into the buffer
>>> R.pop()              #pop a single character
>>> R.write("bcdef")     #fill buffer with many characters at once
>>>            #read many characters at once
>>>            #returns an empty string if the buffer is empty


For the interested, this has been implemented as a pure C extension. The ring buffer itself is implemented as a fixed length array of chars (8-bit signed), dynamically allocated on the Python Heap on instantiation of a buffer. Read and write indexes both increase monotonically, and addresses in the array are determined using index % (modulo) buffer size. Writing more than the buffer size at once throws an exception, otherwise if writing overtakes the read index in the modulo space the buffer contents are silently overwritten.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pyringbuf, version 0.1b2
Filename, size File type Python version Upload date Hashes
Filename, size pyringbuf-0.1b2.tar.gz (3.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page