Main Content

In-Place Memory Optimization

In-place optimization is a memory optimization technique that uses a single buffer, that is, the same memory to store the input and output data. Every time there is an intermediary output value in the algorithm, the same buffer is overwritten to store this value. This technique optimizes the memory usage and generates code that uses very less memory.

These features in DSP System Toolbox™ support in-place memory optimization.

To illustrate the technique of in-place optimization, consider this model that contains a sequence of three, connected Discrete FIR Filter blocks. Each block filters the input it receives and generates an output that is of the same size as the input.

Three Discrete FIR Filter blocks are connected to each other in a sequence. Each block is labelled. The first block is named Discrete FIR Filter, second block is named Discrete FIR Filter1, and the last block is named Discrete FIR Filter2. The input port of the first block is connected to an Inport block. The output port of the last block is connected to an Outport block.

When you generate code from such a model, you can see the in-place optimization in the generated code.

This section shows the in-place optimized generated code. The three for loops with the iteration index n correspond to the respective Discrete FIR Filter block in the Simulink® model. In each of these three for loops, the filter output is computed and stored in the m3fir_Y.Output[] buffer. The m3fir_Y.Output[] buffer rewrites its value every time the Discrete FIR Filter block has an updated output.

This image shows a sequence of for loops in the in-place optimized generated code. The first two for loops control the iteration over the number of input channels and the samples in each channel. The first for loop with the iteration index n corresponds to the first Discrete FIR Filter block.

This image contains two for loops with the iteration index n. These loops correspond to the last two Discrete FIR Filter blocks.

The generated code reuses the output buffer and hence is efficient and uses less memory.

When you generate code from a MATLAB® algorithm containing a sequence of dsp.FIRFilter objects, you see a similar optimization in the generated code.

See Also

Functions

Related Topics