Texas Instruments TMS320 User Manual page 189

Dsp/bios v5.40
Hide thumbs Also See for TMS320:
Table of Contents

Advertisement

5.1.5
Getting the Status of a Memory Segment
5.1.6
Reducing Memory Fragmentation
Buffers can be allocated and freed from a pool as needed at run-time using
the BUF_alloc and BUF_free functions.
The advantages of allocating memory from a buffer pool instead of from the
dynamic memory heaps provided by the MEM module include:
❏ Deterministic allocation times. The BUF_alloc and BUF_free functions
require a constant amount of time. Allocating and freeing memory
through a heap is not deterministic.
❏ Callable from all thread types. Allocating and freeing buffers is atomic
and non-blocking. As a result, BUF_alloc and BUF_free can be called
from all types of DSP/BIOS threads: HWI, SWI, TSK, and IDL. In
contrast, HWI and SWI threads cannot call MEM_alloc.
❏ Optimized for fixed-length allocation. In contrast MEM_alloc is
optimized for variable-length allocation.
❏ Less fragmentation. Since the buffers are of fixed-size, the pool does
not become fragmented.
You can use MEM_stat to obtain the status of a memory segment in the
number of minimum addressable data units (MADUs). In a manner similar to
MEM_alloc, MEM_calloc, and MEM_valloc (refer to Example 5-3), the size
used and length values are returned by MEM_stat.
If you are using the BUF module, you can call BUF_stat to get statistics for a
buffer pool. You can also call BUF_maxbuff to get the maximum number of
buffers that have been used in a pool.
As mentioned previously, using the BUF module to allocate and free fixed-
length buffers from buffer pools reduces memory fragmentation.
Repeatedly allocating and freeing variable-size blocks of memory can lead to
memory fragmentation. When this occurs, calls to MEM_alloc can return
MEM_ILLEGAL if there is no contiguous block of free memory large enough
to satisfy the request. This occurs even if the total amount of memory in free
memory blocks is greater than the amount requested.
To minimize memory fragmentation when allocating variable-size memory
blocks, you can use separate memory segments for allocations of different
sizes as shown in Figure 5-1.
Memory and Low-level Functions
Memory Management
5-7

Advertisement

Table of Contents
loading

Table of Contents