Memory Management
5-6
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.
If no alignment is necessary, align should be 0. MEM’s implementation aligns
memory on a boundary equal to the number of words required to hold a
MEM_Header structure, even if align has a value of 0. Other values of align
cause the memory to be allocated on an align word boundary, where align is
a power of 2.
MEM_free frees memory obtained with a previous call to MEM_alloc,
MEM_calloc, or MEM_valloc. The parameters to MEM_free—segid, ptr, and
size—specify a memory segment, a pointer, and a block size respectively, as
shown in Example 5-5. The values of these parameters must be the same as
those used when allocating the block of storage.
Example 5-5.
Using MEM_free to Free Memory
Example 5-6 displays a function call which frees the array of objects allocated
in Example 5-5.
Example 5-6.
Freeing an Array of Objects
5.1.4.2 Memory Allocation with the BUF Module
The BUF module maintains pools of fixed-size buffers. These buffer pools
can be created statically or dynamically. Dynamically-created buffer pools are
allocated from a dynamic memory heap managed by the MEM module. The
BUF_create function creates a buffer pool dynamically. Applications typically
create buffer pools statically when size and alignment constraints are known
at design time. Run-time creation is used when these constraints vary during
execution.
Within a buffer pool, all buffers have the same size and alignment. Although
each frame has a fixed length, the application can put a variable amount of
data in each frame, up to the length of the frame. You can create multiple
buffer pools, each with a different buffer size.
Void MEM_free(segid, ptr, size)
Int segid;
Ptr ptr;
Uns size;
MEM_free(SRAM, objArr, sizeof(Obj) * ARRAYLEN);
Summary of Contents for TMS320 Series
Page 1: ...TMS320 DSP BIOS v5 40 User s Guide Literature Number SPRU423G April 2009 ...
Page 16: ...xvi ...
Page 152: ...Tasks 4 48 Figure 4 12 Trace from Example 4 7 ...
Page 168: ...Semaphores 4 64 Figure 4 14 Trace Results from Example 4 11 ...
Page 202: ...5 20 ...
Page 287: ...Index 9 Index Void 1 11 W words data memory 3 15 of code 1 5 wrapper function 2 29 ...
Page 288: ...Index 10 Index ...