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

MicroPython • Unable to allocate memory on a raspberry pico w

$
0
0
I have this very annoying problem where I'm trying to create an SSL socket and it fails with a `ENOMEM` error.

I previously went into a rabbit hole and found out that `ussl.wrap_socket()` requires 16kb of continuous memory to be available otherwise it throws the `ENOMEM` error regardless of how much actual free memory there is.

So to combat this now I'm trying to allocate 32kb in the very beginning of my program and then release it right before I attempt to wrap the socket, like this:

Code:

    # this is the very first line of my scriptMEM_RESERVE = bytearray(32768)    # later on ...del(MEM_RESERVE)gc.collect()sock = ussl.wrap_socket(sock)
However, this still gives me `MemoryError: memory allocation failed, allocating 32768 bytes`, also regardless of having upwards of 100kb of free memory.

This tells me that the memory must be fragmented even before my program begins to run?

What can I do to resolve this issue?

Statistics: Posted by pico_nub_qq — Sat Jan 11, 2025 12:30 pm — Replies 4 — Views 122



Viewing all articles
Browse latest Browse all 4610

Trending Articles