Advertisement.
EnchantedLearning.com is a user-supported site.
As a bonus, site members have access to a banner-ad-free version of the site, with print-friendly pages.
Click here to learn more.
(Already a member? Click here.)
Segments in Executable Programs
The text segment, the data segment, and the stack
In a SPARC system, when a program is executed, three areas of memory are allocated for that program's use: the text segment, the data segment, and the stack.
The text segment
The text segment is an area of memory that is set up to be read-only. The contents of this segment are initialized by copying a portion of the executable file itself.
The usage of the text segment is determined by the fact that it is read-only; the program cannot change any of the values stored there. The text segment contains:
- Executable code (in other words, the actual machine-language instructions of the program).
It is very common in modern computing systems for most code to be set up to be read-only. Self-modifying code and code produced on the fly are very tricky to debug, verify, and maintain. Extra speed can often be gained if code is known not to be changeable during program execution (code in a loop can be cached in fast memory, for instance).
- Constant data (values used in the program that will never change).
The most common example of this is a string literal such as "Hello".
If a particular program is being executed in a time-sharing system by more than one person at the same time, memory can be saved by having everybody share a single copy of the text segment.
Type the command w on a Unix system to see what command each currently logged-in user is running. You may be surprised how many people are running the same program at the same time -- popular programs often include csh, pine, slirp, telnet, ftp, and trn.
The data segment
The data segment is an area of memory that can be both read and written by the program; that is, it contains global variables.
Similarly to the text segment, a portion of the executable file is copied to the data segment when a program is about to be executed. This portion is called the initialized data.
The executable file may also specify that the actual data segment is to be even longer than the copied data; the extra part is initialized to all zeros. Since you can't specify initial values for variables stored here, this extra part is often called the uninitialized data, even though in fact it's initialized to all zeros.
During program execution, the data segment may be enlarged even more if the program requests additional memory.
The stack
The stack is an area of memory set aside for local variables which are allocated when a function is called and which are de-allocated when that function returns. (This includes the automatic variables of C, and it may include the return address and other registers saved when a function is called.)
Don't confuse local variables with the processor's local registers, which are completely different.
Copyright 1998-1999 Enchanted Learning Software.
Enchanted Learning Search
Search the Enchanted Learning website for:
|
Advertisement.
Advertisement.