Initialising bytearray at specific memory boundary #12095
Unanswered
czarnikjak
asked this question in
RP2040 / Pico
Replies: 2 comments 5 replies
-
To do that, I think you are going to have to reserve some memory separate from the MicroPython heap (using the linker script). You could then use the There isn't a way to tell the existing allocator about what kind of alignment you need. |
Beta Was this translation helpful? Give feedback.
5 replies
-
You may need to use the uctypes module: https://docs.micropython.org/en/v1.9.3/pyboard/library/uctypes.html |
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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a way to Initialise a Byte Array at a memory address which is a multiple of its size? ie 1k bytearray starting at 1k memory boundary.
I have a workaround where I initialise an array twice the size of what I need and start writing to it at an offset, but that wastes memory:
myArray = bytearray(2048) #need to write 1024 bytes, but have to allocate 2048
modulo = (uctypes.addressof(myArray)) % 1024
startOffset = (uctypes.addressof(myArray)- modulo + 1024) #element of an array at memory location which is a multiple of 1024
Its OK for 1k, but i will need 32k byterray, that approach would waste a lot of memory.
Any ideas if its possible to do it without allocating bigger array? Or a way to trim the beginning and the end of the array without Python relocating it again?
Beta Was this translation helpful? Give feedback.
All reactions