home | list info | list archive | date index | thread index

Re: [OCLUG-Tech] Programming Question re: namespace ??

Hi Ross;

On Mon, 2007-08-20 at 12:21 -0700, Ross Jordan wrote:

> To some degree, this is more a question about how an operating system
> and support libraries organize their ram than how a compiler organizes
> its ram.
> 
> Operating systems provide primitives to allocate virtual memory. malloc
> itself is usually a front end for a user-side (C runtime) library which 
> manages large chunks of VM (this is called th

> -Ross
> e heap). [Section 8.7 of
> K&R C 2nd ed. gives an example]. The various segments come from the 
> linker, are are also somewhat system dependent (could target different 
> binary formats -- a.out / elf / PE). The stack is local memory for a 
> thread typically managed by the kernel.
> 
True Ross.  However, at this point I thought it went without saying I am
using Linux, programming in C, using standard libraries and compiling
with gcc.

C is a structured language with all its parts maintaining a relationship
to each other.  It only has statements, expressions, variables (&
constants), operators and 30 key words.  Library calls and linkages
simply introduce additional statements, expressions, variables (&
constants), operators and key words.  The compiler arranges those
elements according to 1. Text Segment, 2. Initialized Data Segment,
3. Uninitialized Data Segment, 4. The stack, and, 5. The heap.  Using
gdb one can watch the source code transformed to its final syntax, then
further transformed to assembly and from assembly to binary.  In that
process, a program is ordered within 1., 2., and 3. (above).  With that
being true, the order of the elements of a program are predictable and
thus the elements of a program can be diagrammed for easier
visualization.

The program runs by processing the statements in series; one after the
other, looping and jumping as the current statement requires, but always
returning to where it left off, until it reaches the last statement. An
ancillary or secondary diagram can be used to show the process involving
4. and 5. (above).  

> Usually heap is therefor a subset of VM, as stack is a subset of VM.
> Segments get mapped by the kernel (loader) to VM.
> 
And yes, the ordering takes place at the VM level while in fact elements
may actually reside in non-contiguous memory cells in RAM.  Nonetheless,
wherever the final bits come to rest, it can be visualized as an ordered
schematic.

-- 
Regards Bill