Embedding micropython in applications.

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
hauptmech
Posts: 3
Joined: Fri May 27, 2016 10:52 pm

Embedding micropython in applications.

Post by hauptmech » Fri May 27, 2016 11:46 pm

I'm looking at embedding micropython in an application because it appears to be nicely lightweight.

I'm still reading code and figuring out how things are arranged; I might be misunderstanding stuff.

Does anyone have any recommendations on how to handle micropython memory management on a non-embedded system?

For instance, the unix port does stack checking by marking the application stack. That seems ok for a standalone REPL app but I'm worried that this approach does not work in a big application where the stack may be deep but I still want to handle python stack issues. Is that correct? Is the only way to turn off stack checking? (I seem to hit the bottom of the stack quite often when I write python code so this makes me nervous).

I'm not understanding the MICROPY_ENABLE_GC switch fully either. The unix port seems to be allocating a special heap for uPy. Does this mean the GC is not able to work with the natural heap? If I don't enable the GC does memory just continuously fill up?

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Embedding micropython in applications.

Post by pfalcon » Sat May 28, 2016 4:20 pm

hauptmech, to get people interested, feel free to share details about your application, e.g.: Is it open-source? Does it benefit community?
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Embedding micropython in applications.

Post by dhylands » Sat May 28, 2016 5:54 pm

hauptmech wrote:I'm not understanding the MICROPY_ENABLE_GC switch fully either. The unix port seems to be allocating a special heap for uPy. Does this mean the GC is not able to work with the natural heap? If I don't enable the GC does memory just continuously fill up?
MicroPython was really designed to run on a microprocessor where it owns the entire heap. When running under unix, since the regular heap doesn't use garbage collection, the entire micropython heap is allocated out of the main heap. MicroPython then manages its chunk of memory by using garbage collection.

hauptmech
Posts: 3
Joined: Fri May 27, 2016 10:52 pm

Re: Embedding micropython in applications.

Post by hauptmech » Sat May 28, 2016 9:30 pm

[quote="dhylands"]MicroPython was really designed to run on a microprocessor where it owns the entire heap. [/quote]
This makes sense.

I'm trying to get an idea of what happens when the GC is not used. For instance, are local objects at the end of a function call deleted? Or are they left for the GC to collect and constitute a memory leak when there is no GC? The CPP switch ENABLE_GC implies to me that someone was thinking about how to operate without a GC and may have practiced good (enough) memory discipline. I'm hoping.

A more involved solution (to not having a predifined heap) would be for me to extend the gc so it allocates and manages a list of chunks from the system heap.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Embedding micropython in applications.

Post by dhylands » Sun May 29, 2016 4:36 am

I think that if you disable the GC you get no frees at all (i.e. it massively leaks memory). I think that disabling the GC is only useful for testing.

hauptmech
Posts: 3
Joined: Fri May 27, 2016 10:52 pm

Re: Embedding micropython in applications.

Post by hauptmech » Mon May 30, 2016 6:20 am

ok, good to know.

Post Reply