[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");
        }
    else
        {
        /* 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.