4250
Processes And Memory Organization
Exelis VIS receives many questions about how IDL manages memory use. Since memory is a central issue for any program, these questions are not very surprising.
This Help Article gives you information on Processes And Memory Organization.
Please see additional Help Articles for detailed information on how IDL uses memory:
A process is usually defined as the complete state of an instance of a running program. The address space of a given process is typically divided into three regions:
- CODE
The code segment of a program (also known as the Text Segment) contains the machine instructions for the program. Usually, data for which the type and size are known at compile time are also allocated from this region of memory. This includes strings and other constants, as well as global data (extern and static in C parlance). The code segment usually starts at or near address 0 and does not change size during the lifetime of the process.
- STACK
The stack is a region of memory used to pass data between functions, and to store temporary variables local to a given routine. The stack often starts at a very high address in memory and grows towards smaller addresses. Intuitively, this may seem to waste a large amount of space. However, it does not, because the use of virtual memory means that unused addresses below the stack do not need to be mapped in memory.
Some operating systems place a limit on how large the stack can grow, and will kill the process when this limit is reached. There is no benefit to the IDL user from this limit. IDL users can disable it or raise it to a level where it cannot interfere with their work. However, IDL does not make unusual demands on the stack and this limit is rarely a problem.
- HEAP
Dynamic memory, which is memory allocated by the process at run time, is the most complicated type of memory. It is usually allocated starting just beyond the end of the code segment, and grows up in memory towards the stack. The end of the heap is sometimes called the process break point. On Unix systems, this is adjusted using the sbrk() system call. However, programs rarely call sbrk() directly. Instead, they use a memory allocation package such as
malloc()/free() to manage this task.
All systems place some limit on the maximum size of the heap, if only implicitly in the form of the maximum amount of virtual memory available.
Most operating systems use a signed integer to represent memory addresses, so the maximum address on a 32-bit system is usually 2^31-1, and not 2^32-1 as one might assume. The operating system usually maps itself (or key data structures if not the entire thing) into this additional region --an implementation detail that is transparent to the program.
Review on 12/31/2013 MM