Skip to content

Commit 92a4d24

Browse files
committed
Add a buffer parameter to __init__
Allow usage of a preallocated buffer for the ringbuffer by adding a ``buffer`` parameter to __init__
1 parent 5610f36 commit 92a4d24

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/pa_ringbuffer.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,18 @@ class from the standard library can be used.
7676
:param size: The number of elements in the buffer (must be a
7777
power of 2).
7878
:type size: int
79+
:param buffer: optional pre-allocated buffer to use with RingBuffer
80+
:type buffer: buffer
7981
8082
"""
8183

82-
def __init__(self, elementsize, size):
84+
def __init__(self, elementsize, size, buffer=None):
8385
self._ptr = self._ffi.new('PaUtilRingBuffer*')
84-
self._data = self._ffi.new('unsigned char[]', size * elementsize)
86+
if buffer is None:
87+
self._data = self._ffi.new('unsigned char[]', size * elementsize)
88+
else:
89+
self._data = self._ffi.from_buffer(buffer)
90+
8591
res = self._lib.PaUtil_InitializeRingBuffer(
8692
self._ptr, elementsize, size, self._data)
8793
if res != 0:

0 commit comments

Comments
 (0)