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

allocate() and deallocate() use a memory region header, called memheader,
as part of the calling sequence.  You can build your own local header to
manage memory locally. This structure takes the form:

    struct MemHeader {
        struct Node       mh_Node;
        UWORD             mh_Attributes; /* characteristics of region  */
        struct  MemChunk *mh_First;      /* first free region          */
        APTR              mh_Lower;      /* lower memory bound         */
        APTR              mh_Upper;      /* upper memory bound + 1     */
        ULONG             mh_Free;       /* total number of free bytes */
    };

mh_Attributes
    is ignored by allocate() and deallocate().

mh_First
    is the pointer to the first memchunk structure.

mh_Lower
    is the lowest address within the memory block. This must be a
    multiple of eight bytes.

mh_Upper
    is the highest address within the memory block + 1.  The highest
    address will itself be a multiple of eight if the block was allocated
    to you by allocmem().

mh_Free
    is the total free space.

This structure is included in the include files <exec/memory.h> and
<exec/memory.i>.

The following sample code fragment shows the correct initialization of a
MemHeader structure.  It assumes that you wish to allocate a block of
memory from the global pool and thereafter manage it yourself using
allocate() and deallocate().

     allocate.c 

    How Memory Is Tagged.
    ---------------------
    Only free memory is "tagged" using a memchunk linked list. once
    memory is allocated, the system has no way of determining which task
    now has control of that memory.

If you allocate memory from the system, be sure to deallocate it when your
task exits.  You can accomplish this with matched deallocations, or by
adding a memlist to your task's tc_mementry, or you can deallocate the
memory in the finalPC routine (which can be specified if you perform
addtask() yourself).

 allocating memory at an absolute address 
 adding memory to the system pool