Welcome to Python-flavored Magnum! Please note that, while already being rather stable, this functionality is still considered experimental and some APIs might get changed without preserving full backwards compatibility.

corrade.containers.ArrayView class

Array view

Contents

Provides one-dimensional tightly packed view on a memory range. Convertible both from and to Python objects supporting the Buffer Protocol, with one dimension and stride of 1. See StridedArrayView1D and others for more generic views. ArrayView is immutable, see MutableArrayView for the mutable alterantive. All slicing operations are supported, specifying a non-trivial stride will return StridedArrayView1D instead of ArrayView. Example usage:

>>> a = b'hello'
>>> b = containers.ArrayView(a)
>>> b[2]
'l'
>>> bytes(b[1:4])
b'ell'

Memory ownership and reference counting

Unlike in C++, the view keeps a reference to the original memory owner object in the owner field, meaning that calling del on the original object will not invalidate the view. Slicing a view creates a new view referencing the same original object, without any dependency on the previous view. That means a long chained slicing operation will not cause increased memory usage.

>>> b.owner is a
True
>>> b[1:4][:-1].owner is a
True

The owner is None if the view is empty.

Comparison to Python’s memoryview

The ArrayView class is equivalent to one-dimensional memoryview with a stride of 1. For multiple dimensions and non-trivial strides, StridedArrayView1D and friends provide a superset of memoryview features.

Special methods

def __bytes__(self, /) -> bytes
Convert to bytes
def __getitem__(self, arg0: int, /) -> str
Value at given position
def __getitem__(self, arg0: slice, /) -> object
Slice the view
def __init__(self, /) -> None
Default constructor
def __init__(self, arg0: buffer, /) -> None
Construct from a buffer
def __len__(self, /) -> int
View size

Properties

owner: object get
Memory owner object