How Much Memory Can You Allocate?
Run the following program to see how much memory you can allocate in your process.
#include <stdio.h>
#include <stdlib.h>
main() {
int Mb = 0;
while ( malloc(1<<20)) ++Mb;
printf("Allocated %d Mb total\n", Mb);
}
The total will depend on the swap space and process limits with which your system was
configured. Can you get more if you allocate smaller chunks than a Mbyte? Why?
To run this program on the memory-limited MS-DOS, allocate 1-Kbyte chunks instead of 1-
Mbyte chunks.
Cache Memory
Cache memory is a further extension of the multi-level store concept. It is a small, expensive, but
extremely fast memory buffer that sits somewhere between the CPU and the physical memory. The
cache may be on the CPU side of the memory management unit (MMU), as it is in the Sun
SPARCstation 2. In this case it caches virtual addresses and must be flushed on each context switch.
(See Figure 7-4.) Or the cache may be on the physical memory side of the MMU, as it is in the
SPARCstation 10. This allows easy cache sharing with multiprocessor CPU's by caching physical
addresses.
Figure 7-4. The Basics of Cache Memory