Skip to content

micro:bit v2 micropython: method to instantiate/reuse persistent 64-byte buffer #13174

Answered by mendenm
burksfamly asked this question in nRF
Discussion options

You must be logged in to vote

@burksfamly you need to see if your getRadioMsgBytes() function has an alternative, which reads into a pre-allocated buffer. SPI, for example, has a read_into() method which uses a pre-allocated buffer. micropython will never really extend a bytearray; instead, it has to create a new one and copy. getRadioMsgBytes is just returning an entirely new buffer and micropython then deallocates the old one since you trampled its name.

note that your line _global_ba[:] = data #... no go, as item assignment is not supported would work fine if you assigned to the memoryview instead, and as long as the RHS was an array, i.e. _global_mv_ba[:] = data.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@burksfamly
Comment options

@mendenm
Comment options

@burksfamly
Comment options

@burksfamly
Comment options

Answer selected by burksfamly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
nRF
Labels
None yet
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy