Updated Memory Manager (markdown)

master
Garrett Berg 2015-03-11 14:11:11 -06:00
rodzic 9b505a974e
commit 9d17aa316b
1 zmienionych plików z 8 dodań i 0 usunięć

@ -4,6 +4,14 @@ The current memory manager is in `py/gc.c` and is almost a textbook implementati
Resources:
- wikipedia article on [Trace/sweep garbage collection](http://en.wikipedia.org/wiki/Tracing_garbage_collection)
## Wishlist
- [Eliminate heap-memory fragmentation](http://forum.micropython.org/viewtopic.php?f=3&t=455)
When running for an extended period of time (usually after allocating large buffers), the heap can become very fragmented, and although there is enough free memory for an allocation, the free memory is not contiguous (all in a row). Such a problem severely limits uPy's use in critical and long-running applications (eg a web server, a quadcopter). Code running on a microcontroller needs to be a lot more robust than desktop software running on a PC, and so special care must be taken to design a robust memory allocator.
It's not clear how to improve uPy's current memory allocator so that fragmentation is reduced. Ultimately I would want to see a solution that completely eliminates fragmentation, so that programs are guaranteed to run indefinitely. Note that heap fragmentation is not because of the use of garbage collection: even with reference counting, or explicit free, you still have the same amount of fragmentation. The 2 ideas I have to eliminate fragmentation are: 1) a copying memory manager/garbage collector, that can move parts of the heap around so as to make contiguous regions available; 2) a fixed-block memory manager than allocates a single block size (eg 16 bytes), and if you want more you must chain multiple blocks (like a filesystem). Both of these ideas are difficult to implement, and will come with a speed and memory cost. But the cost will be worth it if we can get guaranteed memory allocation.
# `py/gc.c` File documentation
## User Level Functions
The main functions that a user needs are:
`gc_alloc` -- malloc with gc