Towards possibility of precise garbage collector
It seems that many approaches of further evolution of GC in uPy depend on being able to do precise GC, i.e. tell which fields with an object are pointers are which are not. To achieve this, each allocated memory block has to be explicitly typed (and from type, internal layout can be inferred). Way to achieve this while staying compatible with conservative GC and without updating code largely is to have to set of memory allocation routines: one set is to deal with uPy objects (which already have type header is structure member) and another set to deal with "raw" memory allocations (which will need type header added implicitly for precise GC, and nothing added for conservative GC).
We currently have ~dozen functions to do memalloc. The above means doubling them. Other approach would be to reserve all current functions to uPy objects, add just add 2 funcs for "raw" memory: m_malloc() (will use implicit "all pointers inside" type) and m_malloc_typed() which takes explicit type for allocation.
Other thoughts?
Make garbage collector built on malloc / free implementation with pointer indirection
This is a point that was brought up in the tinymem forum thread, where @pfalcon said:
Making uPy GC pluggable, so it can work with system heap (or any external memory manager) is a worthy aim to follow.
This issue is meant to address this, while simultaneously addressing a separate issue associated with the tinymem library -- that it uses pointer indirection to do it's defragmentation, and therefore all calls to pointers need to be wrapped in a tm_void() function call (in some way)
The way to solve this would be:
- make the underlying structure of the memory manager use a macro like
base_allocandbase_freethat could be adjusted depending on the memory manager used - have all pointers pass through macros. So, for example, instead of saying
uint8_t *dynamically_allocated_pointeryou would saymemptr_uint8_p(index)-- which would convert it to a pointer for you.
This is necessary to plugin into custom memory allocators, like the one I am developing for uPython, the tinymem memory manager