Say I have very large bytes object (after loading binary file) and I want to read parts by parts and advance the starting position until it meets the end. I use slicing to accomplish this. I'm worried that python will create completely new copy each time I ask for a slice instead of simply giving me the address of the memory pointing to the position I want.
Simple example:
data = Path("binary-file.dat").read_bytes()
total_length = len(data)
start_pos = 0
while start_pos < total_length:
bytes_processed = decode_bytes(data[start_pos:]) # <---- ***
start_pos += bytes_processed
In the above example does python creates completely new copy of bytes object starting from the start_pos
due to the slicing. If so what is the best way to avoid data copy and use just a pointer to pass to the relevant position of the bytes array.