Real Time Systems Design And Analysis

Chapter 7.8 - Reducing Memory Utilization

7.8   REDUCING MEMORY UTILIZATION

As mentioned previously, memory utilization3 is less of a problem than it has been
in the past, but occasionally a system needs to be designed in which the available
main memory is small in relation to the program size. Moreover, it is expected
that this situation will arise more frequently in the future, as ubiquitous and
mobile computing applications call for very small processors with tiny memories.
Most of the approaches developed to reduce memory utilization date from a time
when memory was at a premium and might violate the principles of software
engineering. Thus, they should be used with caution.

7.8.1   Variable Selection

Memory utilization in one area can be reduced at the expense of another. For
example, all automatic variables (variables that are local to procedures) increase
the loading in the stack area of memory, whereas global variables appear in
the RAM area. By forcing variables to be either local or global, relief can be
purchased in one area of memory at the expense of the other, thus balancing the
memory load.

In addition, intermediate result calculations that are computed explicitly require
a variable either in the stack or the RAM area, depending on whether it is local or
global. The intermediate value can be forced into a register instead by omitting
the intermediate calculation. To illustrate, consider this C code fragment that
calculates one root of a quadratic:

discriminant =b*b-4*a*c;
root=(-b+sqrt(discriminant))*0.5/a;


this code could be replaced by

root=(-b+sqrt(b*B-4*a*c)*0.5/a;

which saves one floating-point variable and thus at least 4 bytes of memory.
In addition, this eliminates at least one STORE macroinstruction, reducing time-
loading as well.

7.8.2   Memory Fragmentation

Memory fragmentation does not impact memory utilization, but it can produce
effects resembling memory overloading. In this case, although sufficient memory
is available, it is not contiguous. Although compaction schemes were discussed
in Chapter 3 and it was noted that they were not desirable in real-time systems,
they may be necessary in serious cases of memory overutilization.

______________________________
3Earlier editions of this book included discussions of the once necessary and accepted techniques of
self-modifying code and reusing global memory. While it was possible to retain these discussions
for historical and entertainment purposes, there is no place for these techniques in modern software
engineering.

 

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: PCMCIA Memory Cards
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.