ram usage

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
Posts: 65
Joined: Tue Jan 22, 2019 2:16 am

ram usage

Post by smhodge » Thu Apr 02, 2020 9:16 pm

I have been using mem_info() to look at memory usage, but that prints to the USB connection. Is there a way to access the same info from within my code?

Posts: 78
Joined: Fri Sep 11, 2015 10:47 pm
Location: Italy

Re: ram usage

Post by pagano.paganino » Thu Apr 02, 2020 11:06 pm

You can try this:

Code: Select all

import io
import os

class DUP(io.IOBase):

    def __init__(self, s):
        self.s = s

    def write(self, data):
        self.s += data
        return len(data)

    def readinto(self, data):
        return 0

s = bytearray()

User avatar
Posts: 1633
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: ram usage

Post by jimmo » Fri Apr 03, 2020 1:06 am

The main useful stats from micropython.mem_info() is the "GC: total: 2072832, used: 3264, free: 2069568" line.
You can get these three numbers using "gc.mem_alloc()" and "gc.mem_free()"

But if you want the other stats, then yeah the dupterm idea works nicely :)

Posts: 65
Joined: Tue Jan 22, 2019 2:16 am

Re: ram usage

Post by smhodge » Fri Apr 03, 2020 2:32 am

Those 3 numbers are all I'm looking for. Thanks

Post Reply