kernel : malloc, free & lsmem

malloc & free

Malloc & free are available in the kernel. For instance telestrat cc65 target uses its internal malloc function. Anyway, it’s possible to use malloc & free in assembly with kernel primitive.

When the malloc is done, it returns a pointer (or null if it’s not possible to do the malloc). When the process starts malloc is done, but when it stops, the kernel flush all malloc done by this process.

It means that’ free’ is done when the process is finished.

lsmem

lsmem is a tool which displays malloc table. In normal use, there is always one line “free” displayed. But when you type a command and this command does a malloc call, malloc table is populated. If something is wrong with free primitive, you will see a line “busy” it means that kernel did not free the “chunk”. Free primitive is not perfect and when memory is too much fragmented, kernel won’t release all the ram. The problem is that free primitive is not recursive in all “free chunks”. It could be corrected in the future.

Be the first to comment

Leave a Reply

Your email address will not be published.


*