Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8026

MicroPython • Re: MemoryError: memory allocation failed, allocating 8192 bytes

$
0
0
I think I've found the part of the code that consumes a lot of memory, at least more than what I expected.
I actually want to do the following

Code:

Q1:      170    255    31    15     .........up till (230 times)...........     63convert to:row1:    10101010 11111111 00011111 00001111 .........up till (230 times)........... 00111111
and I use the following code for that:
I don't know what exactly is happening, I grabbed this piece of code from the internet.

Code:

row1 = []for byte in Q1:# Q = rowbyte        for x in (128, 64, 32, 16, 8, 4, 2, 1):                 row1.append(int(bool(byte & x)))print("row 1",row1)
when i take a look in the shell to row1 (is printed) then i see:
Image
row1 consists of 5521 characters, so I think:
230 x 8 = 1840 bits,
plus the comma and plus the space makes 1840 x 3 = 5520 characters :cry:
I actually expect 230 x 8 = 1840 bits there.

so my conversion from bytes to bits is not efficient enough.
although it does work in the code.

How can I do that more efficiently?
Tnx.

Statistics: Posted by trixo — Sun Nov 03, 2024 10:35 am



Viewing all articles
Browse latest Browse all 8026

Trending Articles