The following material is some background and related discussion; you can skip it if you like.
The Notion of Space
- Since we''ll be using the term namespace, we may as well kill two birds with one stone and address the notion of space in general
with respect to programs and languages.
- Loosely speaking, a space is an area where an identifying label is understood without any further specification.
- An example is the best guide here:
- in the restricted area of our classroom, most of us can go by our first names only (unless there are two of
us with the same first name — which is the perfect example of a name clash).
- However, in a larger context (for example the college or outside world in general) a first name is insufficient, it must be
qualified with a last name (and in a really large context usually something further like a date of birth)
- The notion is a space is similar, and we will use it in two contexts address space and name space.
Address Spaces
- An address space is a context within which a particular address always refers to the same location and outside of which, the address needs to be further qualified
- An everyday example: within the same town, there is (or should be) only one Main Street; thus the address 23 Main Street is unique within
the address space of the town.
- If you're dealing with several towns, this is no longer the case; the above address is probably not unique; it needs further qualification
(for example by specifying the town).
- Under modern day operating systems (e.g. Unix or Windows), each program runs in its own address space, i.e., two programs referring to the same
address are in actuality referring to separate locations in the machine's memory (you learn more about this in an Operating Systems course).
- This notion is vital to the successful operation of a computer running several programs at the same time; if two independent programs shared
addresses, bugs in one program (i.e., a rogue subscript that assigns a value to a location outside the bounds of an array (thus corrupting it)
would affect the execution of the other.
- It's hard enough debugging such an error in the context of the single program; doing so having to worry about what OTHER programs do
would make it nearly impossible; the error would only occur when the other program is running and manifests its error.
- Certain systems have facilities that allows programs to share portions of their address space (for purposes of communication with each
other.
- The basic idea to come away with from the above is that an address space provides a way of isolating the address of a program: within the space, the addresses
are understood, outside, they are not known (and if ARE understood, refer to a totally different location).