Remove imported module from RAM

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
kevinkk525
Posts: 876
Joined: Sat Feb 03, 2018 7:02 pm

Re: Remove imported module from RAM

Post by kevinkk525 » Sun Sep 23, 2018 4:59 pm

oh I did not see that file the first time. The file is 2MB big, has a lot in it. QSTRs of all my modules and strings, a lot of (const bytes*), a lot of these:

Code: Select all

// frozen bytecode for file _testing/utils/subscribe_file.py, scope _testing_utils_subscribe_file__lt_module_gt__printMemory
STATIC const byte bytecode_data__testing_utils_subscribe_file__lt_module_gt__printMemory[53] = {
    0x08, 0x00, 0x00, 0x01, 0x00, 0x01, 0x0c,
    MP_QSTR_printMemory & 0xff, MP_QSTR_printMemory >> 8,
    MP_QSTR__testing_slash_utils_slash_subscribe_file_dot_py & 0xff, MP_QSTR__testing_slash_utils_slash_subscribe_file_dot_py >> 8,
    0x81, 0x11, 0x20, 0x29, 0x33, 0x00, 0x00, 0xff,
    0x1c, MP_QSTR_gc & 0xff, MP_QSTR_gc >> 8,
    0x1e, MP_QSTR_mem_free & 0xff, MP_QSTR_mem_free >> 8,
    0x66, 0x00, 
    0xc1, 
    0x1c, MP_QSTR_print & 0xff, MP_QSTR_print >> 8,
    0x17, 0x01, 
    0x1e, MP_QSTR_format & 0xff, MP_QSTR_format >> 8,
    0xb0, 
    0xb1, 
    0x1c, MP_QSTR_memory & 0xff, MP_QSTR_memory >> 8,
    0xf2, 
    0x66, 0x02, 
    0x64, 0x01, 
    0x32, 
    0xb1, 
    0x25, MP_QSTR_memory & 0xff, MP_QSTR_memory >> 8,
    0x11, 
    0x5b, 
};
I guess I should not post all of it :D

frozen.c however is completely empty.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Re: Remove imported module from RAM

Post by jickster » Mon Sep 24, 2018 1:19 am

Ok then you’re doing all you can to save RAM.

If your .py in frozen_mpy.c doesn’t create any objects when being imported - lists, etc - it should occupy almost no RAM.



Sent from my iPhone using Tapatalk Pro

kevinkk525
Posts: 876
Joined: Sat Feb 03, 2018 7:02 pm

Re: Remove imported module from RAM

Post by kevinkk525 » Mon Sep 24, 2018 7:42 am

I try to avoid having lists as they have to be reallocated when appending items, but I have a lot of classes, class instances and functions.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Post Reply