Run time memory organization


S

sulekha

Hi all,

I was reading the book "Write Great Code vol 1" by Ryndall hyde
in this book chapter 11 is named as Memory architecture &
Organization. in this chapter there is a section named "Run time
memory organization"

author goes on to say that the run time memory is divided into
different sections namely

1) The code section (which holds programs machine instructions)
2) The constant section
(which holds compiler generated read only data)
3) The read only data section,that holds user-defined data that only
be read, never written

4) the static section ,which holds user defined ,initialized static
variables

5) The BSS section ,that holds user-defined un - initialized variables

6) The stack section, where program keeps local variables & other
temporary data

7) The heap section , where program maintains dynamic variables

8) the section reserved for O.S

Most of the time , a given application can live with the default
layouts chosen for these sections by the compiler and linker/loader

In some cases, however , knowing the memory layout can allow you to
develop shorter programs.

for ex , as the code section is usually read only , it may be possible
to combine the code,constants, and read-only data sections into a
single section , thus saving any padding space that the compiler/
linker may place between those sections.


Now my question is as follows can anybody give examples for the above
statement??
 
Ad

Advertisements

J

jacob navia

sulekha said:
Hi all,

I was reading the book "Write Great Code vol 1" by Ryndall hyde
in this book chapter 11 is named as Memory architecture &
Organization. in this chapter there is a section named "Run time
memory organization"

author goes on to say that the run time memory is divided into
different sections namely

1) The code section (which holds programs machine instructions)
2) The constant section
(which holds compiler generated read only data)
3) The read only data section,that holds user-defined data that only
be read, never written

4) the static section ,which holds user defined ,initialized static
variables

5) The BSS section ,that holds user-defined un - initialized variables

6) The stack section, where program keeps local variables & other
temporary data

7) The heap section , where program maintains dynamic variables

8) the section reserved for O.S

Most of the time , a given application can live with the default
layouts chosen for these sections by the compiler and linker/loader

In some cases, however , knowing the memory layout can allow you to
develop shorter programs.

for ex , as the code section is usually read only , it may be possible
to combine the code,constants, and read-only data sections into a
single section , thus saving any padding space that the compiler/
linker may place between those sections.


Now my question is as follows can anybody give examples for the above
statement??

This is the task of the linker. It is that piece of software that
builds the different sections you mention. I think any example
written in C will never show you what you want to see since the
compiler will translate the code into directives for the linker
and you have no control of how this is done.

Some linkers, specifically GNU ld have a scripting language of sorts
where they accept instructions as to how to layout the program sections.
See the GNU documentation if you want more information about that,
but I can tell you, that language is only for the linker developers...

I would follow the implicit advise of the sentence you quote:
 
S

santosh

sulekha said:
Hi all,

I was reading the book "Write Great Code vol 1" by Ryndall hyde
in this book chapter 11 is named as Memory architecture &
Organization. in this chapter there is a section named "Run time
memory organization"

<snip rest>

Standard C, (which is the primary topic of this group), has no knowledge of
binary formats and runtime memory layouts. Since your question is
intrinsically architecture specific and involves some knowledge of assembly
language, you should ask in <and
<
BTW, Randall Hyde is a "regular" in both the above groups, so you'll get the
information straight from the "horse's mouth", so to speak.
 
B

banu

<snip rest>

Standard C, (which is the primary topic of this group), has no knowledge of
binary formats and runtime memory layouts. Since your question is
intrinsically architecture specific and involves some knowledge of assembly
language, you should ask in <and
<
BTW, Randall Hyde is a "regular" in both the above groups, so you'll get the
information straight from the "horse's mouth", so to speak.

ya i think this can be done in 80x86 0r 80x85 assembly programming
only. there u have quite a control over choosing the range of memory
addresses.

regards,
varun
 
Ad

Advertisements

C

CBFalconer

sulekha said:
I was reading the book "Write Great Code vol 1" by Ryndall hyde
in this book chapter 11 is named as Memory architecture &
Organization. in this chapter there is a section named "Run time
memory organization"

author goes on to say that the run time memory is divided into
different sections namely

1) The code section (which holds programs machine instructions)
2) The constant section
(which holds compiler generated read only data)
3) The read only data section,that holds user-defined data that
only be read, never written
4) the static section ,which holds user defined ,initialized
static variables
5) The BSS section, that holds user-defined un - initialized
variables
6) The stack section, where program keeps local variables &
other temporary data
7) The heap section, where program maintains dynamic variables
8) the section reserved for O.S

This organization applies to some particular implementation of C,
and is not in the least general. If you want comments on it you
need to go to a newsgroup that deals with that implementation, not
c.l.c. Here we deal with the language as defined in the ISO and
ANSI standards, and earlier by K&R. Variables can exist in static,
auto, or dynamic storage, but how those are implemented is not
defined. How they act is. Code lives in some sort of magic space.
 

Top