www.ti.com

Data Memory

Notice that both a() and b() freely use some of the same scratch registers and no saving and restoring of these registers is necessary. This is possible because both functions, a() and b(), agree on the set of scratch registers and that values in these registers are indeterminate at the beginning of each function.

By analogy, we partition all memory into two groups: scratch and persistent.

Scratch memory is memory that is freely used by an algorithm without regard to its prior contents, i.e., no assumptions about the content can be made by the algorithm and the algorithm is free to leave it in any state.

Persistent memory is used to store state information while an algorithm instance is not executing.

Persistent memory is any area of memory that an algorithm can write to assume that the contents are unchanged between successive invocations of the algorithm within an application. All physical memory has this behavior, but applications that share memory among multiple algorithms may opt to overwrite some regions of memory (e.g., on-chip DARAM).

A special variant of persistent memory is the write-once persistent memory. An algorithm'sinitialization function ensures that its write-once buffers are initialized during instance creation and that all subsequent accesses by the algorithm'sprocessing to write-once buffers are strictly read-only. Additionally, the algorithm can link its own statically allocated write-once buffers and provide the buffer addresses to the client. The client is free to use provided buffers or allocate its own. Frameworks can optimize memory allocation by arranging multiple instances of the same algorithm, created with identical creation parameters, to share write-once buffers.

Note that a simpler alternative to declaring write-once buffers for sharing statically initialized read-only data is to use global statically linked constant tables and publish their alignment and memory space requirements in the required standard algorithm documentation. If data has to be computed or relocated at run-time, the write-once buffers approach can be employed.

The importance of making a distinction between scratch memory and persistent memory is illustrated in Figure 2-1.

Figure 2-1. Scratch vs Persistent Memory Allocation

Algorithm A

 

Scratch

 

Algorithm B

 

 

 

 

 

 

 

 

 

Scratch

 

 

Algorithm C

 

 

 

 

 

 

 

 

 

Scratch

 

0

 

 

 

 

 

 

 

 

 

 

Algorithm C 1

 

Scratch

 

Physical

 

 

 

 

 

 

 

 

 

 

 

 

Memory

 

Scratch

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0000

 

 

Persistent A

Persistent B

Write-Once C

Write-Once C

Persistent A

Persistent B

Write-Once C

 

 

 

FFFF

All algorithm scratch memory can be "overlaid" on the same physical memory. Without the distinction between scratch and persistent memory, it would be necessary to strictly partition memory among algorithms, making the total memory requirement the sum of all algorithms'memory requirements. On the other hand, by making the distinction, the total memory requirement for a collection of algorithms is the sum of each algorithm'sdistinct persistent memory, plus any shared write-once persistent memory, plus the maximum scratch memory requirement of any of these algorithms.

SPRU352G –June 2005 –Revised February 2007

General Programming Guidelines

21

Submit Documentation Feedback

Page 21
Image 21
Texas Instruments TMS320 DSP manual Scratch vs Persistent Memory Allocation