# `ArrayBuffer`

digraph inheritance3b80b2d475 { bgcolor=transparent; rankdir=UD; ratio=compress; size="8.0, 12.0"; "ArrayBuffer" [URL="#taurus.core.util.containers.ArrayBuffer",color=dodgerblue1,fillcolor=white,fontcolor=black,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.5,shape=box,style=rounded,target="_top",tooltip="A data buffer which internally uses a preallocated numpy.array."]; }

class ArrayBuffer(buffer, maxSize=0)

  A data buffer which internally uses a preallocated numpy.array. An ArrayBuffer will only present the actual contents, not the full internal buffer, so when appending or extending, it behaves as if dynamic reallocation was taking place.

  The contents of the class:ArrayBuffer can be accessed as if it was a numpy array (i.e slicing notation like b[2:3], b[:,2], b[-1],… are all valid).

  For retrieving the full contents, see `ArrayBuffer.contents()` and `ArrayBuffer.toArray()`

  On creation, a given initial internal buffer and a maximum size are set. If the maximum size is larger than the original internal buffer, this will be automatically grown in geometrical steps if needed to accommodate the contents, up to the maximum size. Once the contents fill the maximum size, appending or extending the contents will result in older contents being discarded (in a FIFO way)

  The `append()` and meth:extend methods are designed to be cheap (especially if the internal buffer size is already at the maximum size), at the expense of memory usage

  Import from `taurus.core.util.containers` as:

      from taurus.core.util.containers import ArrayBuffer

  append(x)

    similar to the append method in a list, except that once the maximum buffer size is reached, elements get discarded on the begginning to keep the size within the limit

    Parameters:

      x (scalar) – element to be appended

    See also

    `extend()`

  bufferSize()

    Returns the current size of the internal buffer

    Returns:

      lcurrent length of the internal buffer

    Return type:

      int

    See also

    `contentsSize()`, `maxSize()`

  contents()

    returns the array of the contents that have already been filled. Note that it does not return the full buffer, only those elements that have been already set.

    It is equivalent to b[:]

    Returns:

      array of contents

    Return type:

      numpy.array

    See also

    `toArray()`

  contentsSize()

    Equivalent to len(b)

    Returns:

      length of the current contents of the ArrayBuffer (not the maximum size of the buffer)

    Return type:

      int

    See also

    `maxSize()`

  extend(a)

    similar to the extend method of a list, except that once the maximum buffer size is reached, elements get discarded on the begginning to keep the size within the limit

    Parameters:

      a (numpy.array) – array of elements to append

    See also

    `append()`, `extendLeft()`

  extendLeft(a)

    Prepends data to the current contents. Note that, contrary to the extent method, no data will be discarded if the maximum size limit is reached. Instead, an exception will be raised.

    Parameters:

      a (numpy.array) – array of elements to append

    See also

    `extend()`

  isFull()

    Whether the contents fill the whole of the internal buffer

    Returns:

      True if the contents fill the maximum size. False otherwise.

    Return type:

      bool

    See also

    `maxSize()`

  maxSize()

    Returns the maximum size of the internal buffer, beyond which the ArrayBuffer starts discarding elements when appending

    Returns:

      maximum length of the internal buffer

    Return type:

      int

    See also

    `contentsSize()`, `append()`, `extend()`, `isFull()`

  moveLeft(n)

    discards n elements from the begginning to make space at the end of the buffer. Moves all elements n positions to the left and the contents size gets decreased by n

    Note: if n is larger or equal than the maximum buffer size, the whole buffer is wiped

    Parameters:

      n (int)

  remainingSize()

    returns the remaining free space in the internal buffer (e.g., 0 if it is full)

    Returns:

      length of the unused space in the internal buffer

    Return type:

      int

    See also

    `contentsSize()`, `maxSize()`,

  resizeBuffer(newlen)

    resizes the internal buffer

  setMaxSize(maxSize)

    Sets the maximum size of the internal buffer, beyond which the ArrayBuffer starts discarding elements when appending

    Parameters:

      maxSize (int) – maximum length of the internal buffer

    See also

    `contentsSize()`, `append()`, `extend()`, `isFull()`

  toArray()

    returns a copy of the array of the contents. It is equivalent to `b.contents.copy()`

    Returns:

      copy of array of contents

    Return type:

      numpy.array

    See also

    `contents()`