Arun Chettoor
Arun Chettoor

Reputation: 1141

Where will the Initialized data segment values are stored before run time?

Normally the data segment in C code resides in the RAM volatile memory and consists of Initialized data segment, Uninitialized data segment(.BSS), Stack memory and the heap.

  1. Stack memory is only coming to picture while on run time call routines and in push and pull of values.

  2. Heap is used on dynamic memory allocation calls malloc, calloc and realloc.

  3. .BSS segment is only having value by memset or inside functions as it doesnot have any genuine initial values .

  4. But the Initialized data segment even though it is static or global must be having some values and these values needs to be stored in a non volatile memory location as it should exist before the running of the code.

Question: In which section of non volatile memory location this initialized values are stored and whether any means we can use to reduce the memory consumption of this?

Upvotes: 3

Views: 4173

Answers (1)

ntshetty
ntshetty

Reputation: 1305

The following two diagrams helps to understand the memory layout of c binary

enter image description here enter image description here

Refer : C compiler. Memory map. Program

Upvotes: 6

Related Questions