MEM_alloc
2-214
C Interface
Syntax
addr = MEM_alloc(segid, size, align);
Parameters
Int
segid;
/* memory segment identifier */
size_t
size;
/* block size in MADUs */
size_t
align;
/* block alignment */
Return Value
Void
*addr;
/* address of allocated block of memory */
Description
MEM_alloc allocates a contiguous block of storage from the memory
segment identified by segid and returns the address of this block.
The segid parameter identifies the memory segment to allocate memory
from. This identifier can be an integer or a memory segment name
defined in the configuration. Files created by the configuration define
each configured segment name as a variable with an integer value.
The block contains size MADUs and starts at an address that is a multiple
of align. If align is 0 or 1, there is no alignment constraint.
MEM_alloc does not initialize the allocated memory locations.
If the memory request cannot be satisfied, MEM_alloc calls SYS_error
with SYS_EALLOC and returns MEM_ILLEGAL.
MEM functions that allocate and deallocate memory internally lock the
memory by calling the LCK_pend and LCK_post functions. If another task
already holds a lock to the memory, there is a context switch. For this
reason, MEM_alloc cannot be called from the context of a SWI or HWI.
MEM_alloc checks the context from which it is called. It calls SYS_error
and returns MEM_ILLEGAL if it is called from the wrong context.
A number of other DSP/BIOS APIs call MEM_alloc internally, and thus
also cannot be called from the context of a SWI or HWI. See the
“Function Callability Table” on page A-2 for a detailed list of calling
contexts for each DSP/BIOS API.
Page Boundary Issues
on the ’C55x
On the ’C55x using the large memory model, MEM objects can configure
heaps larger than 64K MADUs (16-bit words for 'C55x). However,
memory blocks that cross a 64K page boundary cause C compiler errors.
(See the
TMS320C55x Optimizing C Compiler User’s Guide
for details.)
To prevent such errors, you can use the huge memory model. If you use
the large memory model, the remainder of this section applies.
MEM_alloc
Allocate from a memory segment