You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Consider memory alloc API with explicit size param for m_free() #2
When dealing with interpreters, object size size is either implicitly known (for example, basic representation of object has fixed size, like 8 or 32 bytes), or size is stored explicitly on interpreter's level (for example, array size needs to be stored in object header anyway). This means that it may be possible to optimize low-level memory allocation system by not storing memory chunk size (thus saving memory), instead relying that higher levels will pass size explicitly.
Quick look at current sources doesn't show that MicroPython is ideally suited for such optimization, but that's why I write - to propose to add that as a (non-immediate) design goal.
First steps towards that can be simple: make m_free() have signature m_free(ptr, size), and m_realloc(ptr, old_size, new_size), then while going over code to adjust call sites, see if what to pass as "size" param is obvious. In case it's not, well, pass 0, and leave larger refactors to someone who really will implement alternative allocators. Ultimately, there're good reasons for having explicit size field for all variable-length objects, IMHO.
In the current garbage collector (that runs properly only on the MCU), the object size is implicitly known. There is a bitmap at the very start of the heap which indicates which blocks (32 bytes each) are allocated. So an object size can be computed by working out how many blocks are contiguously allocated. There is also a bit to indicate "start of run of blocks".
Okay, I've implemented it as you suggested, with an explicit size parameter for m_free and m_realloc. The macros you should use are m_del, m_del_obj and m_renew.
Activity
dpgeorge commentedon Dec 29, 2013
Good idea.
In the current garbage collector (that runs properly only on the MCU), the object size is implicitly known. There is a bitmap at the very start of the heap which indicates which blocks (32 bytes each) are allocated. So an object size can be computed by working out how many blocks are contiguously allocated. There is also a bit to indicate "start of run of blocks".
dpgeorge commentedon Dec 29, 2013
Okay, I've implemented it as you suggested, with an explicit size parameter for m_free and m_realloc. The macros you should use are m_del, m_del_obj and m_renew.
Merge pull request micropython#2 from micropython/master
atmel-samd: Support ampy get and fix USB dropping characters.
Merge pull request #2 from dhylands/fix-makefile
Merge pull request #2 from micropython/master
Merge pull request #2 from arofarn/master
Merge pull request #2 from adafruit/master
Merge pull request micropython#2 from bergzand/riot_pin_port
Merge pull request micropython#2 from amirgon/master
Merge pull request micropython#2 from littlevgl/pmpp_6_fix
Merge pull request micropython#2 from adafruit/master
5 remaining items
Merge pull request micropython#2 from tannewt/improve_verification
Proposal micropython#2
Merge pull request micropython#2 from adafruit/master
builtinimport: Fix a crash with 'import ulab.linalg' on unix port only
sharpdisplay: Fix memory corruption across soft-reset
Merge pull request micropython#2 from adafruit/main
py/repl: Don't read past the end of import_str.
py/repl: Don't read past the end of import_str.
Merge pull request micropython#2 from smlng/pr_riot_port_freebsd
Merge pull request micropython#2 from hathach/tinyusb-update
Merge pull request micropython#2 from adafruit/main
Fix 3 bugs in arbitrary precision integer division (mpz.c)
py/repl: Don't read past the end of import_str.
submodule pointers: metal self-hosting run micropython#2 (discovery, …