Replies: 3 comments
-
The method in »f5()« is fine. Edit: ba = bytearray(10)
da = bytearray(5)
print(id(ba), id(da))
ba[0:5] = da
print(id(ba), id(da)) |
Beta Was this translation helpful? Give feedback.
0 replies
-
You can also do: def f4(self, buf):
data = bytearray(b'\x00\x04')
buf[:] = data |
Beta Was this translation helpful? Give feedback.
0 replies
-
@GitHubsSilverBullet @jomasnash I have tried |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am writing a device driver which is passed a buffer as an attribute and needs to update the caller's buffer. What is th best way to do this? I am trying to follow the
machine.I2C.readfrom_mem_into
method where the result is written back tobuf
.Any attempt to modify the buffer results in allocation and the result is not written to the caller's buffer. The only way I have found that works is to update the buffer elements individually. In the example below
f4
fails due to allocation, butf5
andf6
work. Is is necessary to use memoryview to guarantee writing to the caller's buffer or is usingbuf[i]
safe?Beta Was this translation helpful? Give feedback.
All reactions