Sharing SPIRAM with Micropython (GC question) #13507
-
Hi, I am working on a C application and require more RAM than what is available internally on the ESP32-S3. My intention is to utilize a portion of the SPIRAM with Micropython. In the main.c file, I came across the following code:
If I reduce Micropython's allocation and use the remaining memory, will GC catch it? The following line made me doubt:
Is it safe to use memory beyond Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
If you reduce An alternative approach is to allocate a block of memory from the micropython heap and hold a reference to it as long as you need it so that it does not get gc-ed. If it is a large block, you should allocate soon after boot to avoid heap fragmentation. This way you can dynamically set the size of memory for your module (if that is useful for your use case). Another approach is to allocate the memory in python code as a bytearray (or other type of array) and pass that to your C module to use. This has the convenience that you can easily inspect the memory from python code while developing and debugging (although there are other ways to expose that memory to python. |
Beta Was this translation helpful? Give feedback.
-
@BrunoESP32 All of this has changed recently. I think you're looking at an older version of the codebase. |
Beta Was this translation helpful? Give feedback.
-
@glenn20 write 'This has the convenience that you can easily inspect the memory from python code while developing and debugging (although there are other ways to expose that memory to python.' |
Beta Was this translation helpful? Give feedback.
If you reduce
mp_task_heap_size
you can reserve the memory above for your C application/module's use. GC wil ignore any memory outside the start and end values passed to gc_init().An alternative approach is to allocate a block of memory from the micropython heap and hold a reference to it as long as you need it so that it does not get gc-ed. If it is a large block, you should allocate soon after boot to avoid heap fragmentation. This way you can dynamically set the size of memory for your module (if that is useful for your use case).
Another approach is to allocate the memory in python code as a bytearray (or other type of array) and pass that to your C module to use. This has the conven…