# Making Assumptions About Memory Types

### What is it:

Assuming that DMA structures can be declared as globals or can be declared on the stack.

### Why it's bad:

In future hardware, the DMA engine may not have access to the memory used to hold globals and the stack.

### What to do

Always allocate structures from the appropriate kind of memory.

## Example and Discussion

There will probably come a day when stack space, globals, and code reside in CPU-only memory, providing vastly improved performance. This memory will probably not be given DMA access, which will cause problems for objects that need this service. Particularly at risk are CCBs and audio buffers. Always allocate the memory for these structures by using `AllocMem()` with the appropriate MemType.

Avoid declarations of the following type:

``

    MyRoutine ()
    {
        CCB    myCel;
            .
            .
            .
    }

Instead, follow this example:

``

    MyRoutine ()
    {
        CCB    *myCel;

        myCel = AllocMem (sizeof (CCB), MEMTYPE_CEL);
            .
            .
            .
        if (myCel) FreeMem (myCel, sizeof (CCB));
    }

It is especially important that you modify your code to anticipate this. The penalty for trying to DMA from non-DMA memory is having your task terminated.