[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 */

    is ignored by Allocate() and Deallocate().

    is the pointer to the first MemChunk structure.

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

    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().

    is the total free space.

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

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().


    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 

[Back to Amiga Developer Docs]