[Contents] [Index] [Help] [Retrace] [Browse <] [Browse >]

To use Intuition's memory functions, first create an anchor for the memory
to be allocated by declaring a variable that is a pointer to a Remember
structure and initializing that pointer to NULL.  This variable is called
the remember key.

    struct Remember *rememberKey = NULL;

Call AllocRemember() with the address of the remember key, along with the
memory requirements for the specific allocation.  Multiple allocations may
be made before a call to FreeRemember().

    memBlockA = AllocRemember(&rememberKey, SIZE_A,
                              MEMF_CLEAR | MEMF_PUBLIC);
    if (memBlockA == NULL)
        /* error: allocation failed */
        printf("Memory allocation failed.\n");
        /* use the memory here */
        printf("Memory allocation succeeded.\n");

AllocRemember() actually performs two memory allocations per call, one for
the memory requested and the other for a Remember structure.  The Remember
structure is filled in with data describing the allocation, and is linked
into the list to which the remember key points.

To free memory that has been allocated, simply call FreeRemember() with
the correct remember key.

    void FreeRemember(&rememberKey, TRUE);

This will free all the memory blocks previously allocated with
AllocRemember() in a single call.

[Back to Amiga Developer Docs]