# Py - memoryview example
# by Anthony Vogelaar, Perth Scotland
# rev 0.10  2026-09-03  initial release

# documentation
#    https://docs.python.org/3/library/stdtypes.html#memory-views

import	sys
from	array	import	array

data = array('I', [0xFF010203, 0xFF040506, 0xFF070809, 0xFF0A0B0C])	# fill array with 4 RGB pixels
mv   = memoryview(data)												# memoryview provides R/W access to data
print('data   :', data)												# print data
print('mv     :', mv.tolist())										# print data through mv
mv_cast = mv.cast('B')
print('mv_cast:', mv_cast.tolist())									# print data through mv_cast as bytes

mv_cast[0] = 100													# Red of data[0] is 100
print('\ndata[0].red = 100\n')

print('mv_cast:', mv_cast.tolist())									# print data through mv_cast as bytes
print('mv     :', mv.tolist())										# print data through mv
print('data   :', data)												# print data

# Python did note make any copies
# memoryviews can be sliced for parameter use

def test(a):
    print(a.tolist())
    
    
test(mv_cast[4:8])		# no copy is made
