Imagine you want to display a list of entries in a directory. You could step through it using Examine()/ExNext() and directly use the MUIM_List_Insert method on your file info block buffer.
Your construct hook will be called with this file info block as parameter, makes a copy of it and returns the address of that copy. Thats what is actually added to the list.
The corresponding destruct hook is called whenever an entry shall be removed. It's task would simply be to free the memory and maybe other resources concering this entry that were allocated by the construct hook.
Using these two functions, you will never have to worry about freeing the memory used by your list entries. Clearing the list or disposing the list object will automatically remove all entries and thus free the associated resources.
The construct hook will be called with the hook
in A0, the data given to
MUIM_List_Insert as message
in register A1 and with pointer to a standard kick 3.x
memory pool in A2. If you want, you can use the exec
or amiga.lib functions for allocating memory within
this pool, but this is only an option.
If the construct hook returns NULL, nothing will be added to the list.
There is a builtin construct hook available called
MUIV_List_ConstructHook_String. This expects that
you only add strings to your list and will make
a local copy of this string to allow you destroying
the original. Of course you must also use
MUIV_List_DestructHook_String in this case.
Without construct and destruct hooks, you are responsible for allocating and freeing entries yourself.