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

MicroPython • Re: Unable to allocate memory on a raspberry pico w

$
0
0

Code:

I just need to be able to reserve a chunk for my socket connection to succeed..
If you can't reserve the memory where you are trying to reserve it, perhaps reserve it earlier, in 'boot.py' ?

If your attempt to reserve 32KB is at the very start of 'main.py' it seems the compilation of that has eaten some 100KB for executable bytecode storage and seemingly, somehow, fragmented the 100KB left such that there isn't a 32KB contiguous block.

You can check that by using 'micropython.mem_info(1)' at the start of 'main.py'.

If it's not fragmented, a 32KB block should be reservable, you would have to ask MicroPython why that is not working.

If it is fragmented you will have to analyse what in you 'main.py' is causing that, figure out a way around that.
That was a smart idea, I tried reserving it in boot.py but now something very strange seems to be happening. My program does not get to run and I get the following memory allocation error:

Code:

MemoryError: memory allocation failed, allocating 342 byte
But when I look up the memory right after, this is what I get:

Code:

>>> import testTraceback (most recent call last):  File "<stdin>", line 1, in <module>MemoryError: memory allocation failed, allocating 342 byte>>> micropython.mem_info(1)stack: 540 out of 7936GC: total: 166016, used: 44352, free: 121664 No. of 1-blocks: 39, 2-blocks: 12, max blk sz: 2048, max free sz: 2306GC memory layout; from 200083d0:00000: h=MhhhhhDAhhB..Dhh.DBDBh===B.B=.h====B=BBBBB.B=B.B=BBB.B=hB.B=Bh...
Doesn't "max free sz: 2306" mean the largest free memory chunk is 2306 bytes? How does it fail to allocate 342? Furthermore there are 121kb of free memory, surely there must be a 342b free chunk..?

Even more, the memory map (or whatever it is) ends with the following:

Code:

1f800: ======..........................................................       (35 lines all free)28800: ........
which means that addresses from 0x1f800 to 0x28800 are free, which is like 36kb?

Statistics: Posted by pico_nub_qq — Wed Jan 15, 2025 10:02 pm



Viewing all articles
Browse latest Browse all 5388

Trending Articles