User`s guide
Memory Management
Memory and Low-level Functions 5-5
5.1.4 Allocating Memory Dynamically
Basic system-level storage allocation is handled by MEM_alloc, whose
parameters specify a memory segment, a block size, and an alignment as
shown in Example 5-3. If the memory request cannot be satisfied, MEM_alloc
returns MEM_ILLEGAL.
Example 5-3. Using MEM_alloc for System-Level Storage
The segid parameter identifies the memory segment from which memory is
to be allocated. This identifier can be an integer or a memory segment name
defined in the Configuration Tool.
The memory block returned by MEM_alloc contains at least the number of
minimum addressable data units (MADUs) indicated by the size parameter.
A minimum addressable unit for a processor is the smallest datum that can
be loaded or stored in memory. An MADU can be viewed as the number of
bits between consecutive memory addresses. The number of bits in an
MADU varies with different DSP devices, for example, the MADU for the
C5000 platform is a 16-bit word, and the MADU for the C6000 platform is an
8-bit byte.
The memory block returned by MEM_alloc starts at an address that is a
multiple of the align parameter; no alignment constraints are imposed if align
is 0. An array of structures might be allocated as shown in Example 5-4.
Example 5-4. Allocating an Array of Structures
Many DSP algorithms use circular buffers that can be managed more
efficiently on most DSPs if they are aligned on a power of 2 boundary. This
buffer alignment allows the code to take advantage of circular addressing
modes found in many DSPs.
Ptr MEM_alloc(segid, size, align)
Int segid;
Uns size;
Uns align;
typedef struct Obj {
Int field1;
Int field2;
Ptr objArr;
} Obj;
objArr = MEM_alloc(SRAM, sizeof(Obj) * ARRAYLEN, 0);










