> > > > I am trying to diagram how memory is used by a program. One of the > things I would like to include in my diagram is the hierarchy of > terminology i.e. what is a sub-set of what. As a general idea a name > space is understandable, but when it comes to actually creating the sets > or hierarchy the description are not clear of what goes where. > > As a side-bar, all the schematics I have found show just five parts to a > C program's arrangement in memory: > 1. Text Segement > 2. Initialized Data Segment > 3. Unitialized Data Segement > 4. The stack > 5. The heap > > I want to be more detailed and show (draw) where each part of an actual > program would be placed at start up and while running (i.e. use of the > stack and heap). At the same time I would like to show the relationship > between VM and actual memory. 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 the 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. Usually heap is therefor a subset of VM, as stack is a subset of VM. Segments get mapped by the kernel (loader) to VM. -Ross