🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Where does all the RAM disappear?

    Micropython
    4
    8
    10.2k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      JackH
      last edited by

      When I check gc.mem_free() after restarting uiflow micropython I get about 80k on a Stickc and Stickc plus. Where is the other 430k?

      Jack
      PS With a bare metal firmware it's over 100k, same question.

      1 Reply Last reply Reply Quote 0
      • R
        robalstona
        last edited by

        Python is a scripting language. You need an interpreter that resides in ram to run the python code. You also need in-memory buffers to read scripts, interpret them, and run bytecode. Add that more program stack and network stack. If you write a program in, say, arduino and compile it, you will have almost all available RAM.

        1 Reply Last reply Reply Quote 0
        • J
          JackH
          last edited by

          Got it, thanks Rob. Any idea how much for the interpreter, the buffers, the bytecode... ?

          Jack

          1 Reply Last reply Reply Quote 0
          • R
            robalstona
            last edited by

            in this screenshot you have how many stack are occupying the ram.

            https://docs.m5stack.com/image/base/APIKEY.webp

            If you need more free ram memory, probably you need compile micropython from scratch and change some parameters in source code.

            J 1 Reply Last reply Reply Quote 0
            • J
              JackH @robalstona
              last edited by

              @robalstona Interesting, thankyou.

              1 Reply Last reply Reply Quote 0
              • M
                mb
                last edited by

                I think an interesting option would be to "compile" the Python code on PC (like Arduino) and then transfer only binaries to the ESP32.

                T 1 Reply Last reply Reply Quote 0
                • R
                  robalstona
                  last edited by

                  @mb You can use python cross compiler to compile source code into pseudo-executable code called bytecode. Which will not reduce the memory already used by python, but it will reduce the memory consumption by compiled .mpy code compared to the .py code itself and the code will be executed faster. In this case, the source code to bytecode translation process is skipped. But any change of source code need again crosscompile and transfer compiled files to device.

                  That's why I like to create programs in micropython. Any change in the program takes a few seconds. (Compared to writing in arduino or esp-idf where every change in the code involves recompiling all the code from scratch and flashing and take some time which is too long for me). But something at the expense of something: faster program development at the expense of operating speed and memory usage.

                  1 Reply Last reply Reply Quote 0
                  • T
                    Thrasher @mb
                    last edited by

                    @mb You need to read a bit about py and c++ difference

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post