[Contents] [index] [Help] [Retrace] [browse <] [Browse >]

If you want to take advantage of Exec's automatic cleanup, use the memlist
and allocentry() facility to do your dynamic memory allocation.

In the task control block structure, there is a list header named
tc_mementry. this is the list header that you initialize to include
memlists that your task has created by call(s) to allocentry().  here is a
short program segment that handles task memory list header initialization
only.  It assumes that you have already run AllocEntry() as shown in the
simple AllocEntry() example above.

    struct Task *tc;
    struct MemList *ml;

    /* First initialize the task pointer and AllocEntry() the memlist ml */

    if(!tc->tc_MemEntry)
        NewList(tc->tc_MemEntry);  /* Initialize the task's memory    */
                                   /* list header. Do this once only! */
    AddTail(tc->tc_MemEntry, ml);

Assuming that you have only used the allocentry() method (or allocmem()
and built your own custom memlist), the system now knows where to find the
blocks of memory that your task has dynamically allocated.  The remtask()
function automatically frees all memory found on tc_mementry.

    createtask() sets up a memlist.
    -------------------------------
    The amiga.lib CreateTask() function, and other system task and
    process creation functions use a MemList in tc_mementry so that
    the Task structure and stack will be automatically deallocated when
    the Task is removed.