Where are static,constant variables stored?

Discussion in 'Embedded Systems and Microcontrollers' started by vinothmct, Sep 27, 2012.

  1. vinothmct

    Thread Starter New Member

    Sep 24, 2012
    14
    0
    I wish to know where data segment is implemented? Is it in RAM or ROM/Flash?

    Our local variables are stored in stack which is implemented in RAM .

    static , global variables are stored in data segmented is it implemnted in RAM? Is it so ? If will it lose contents when power is turned off?

    Heap is implemented in RAM or Flash?
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,148
    1,791
    You don't say which platform and you don't say which compiler or assembler.

    The 'data' segment is normally implemented in RAM. It does lose its contents when the power goes away unless the RAM has a battery backup for the power supply.

    The heap is part of the 'data' segment and shares the same properties as any other data stored in RAM.

    Items declared 'const', 'flash', or 'eeprom' may be stored in non-volatile memory or they may be copied to RAM during initialization. It really depends on the platform and the compiler. So if you want an accurate answer; help us out won't you?
     
  3. MrChips

    Moderator

    Oct 2, 2009
    12,447
    3,363
    Either. It depends on the specific compiler.
    Constants are usually stored in flash. However, compilers install an initialization routine that can initialize RAM variables. Hence the volatility of RAM is not an issue.
     
  4. vinothmct

    Thread Starter New Member

    Sep 24, 2012
    14
    0
    LPCxpresso , IAR embedded Workbench . Does it entirely depend on the compiler? We can find it by reading compiler document?
     
  5. Papabravo

    Expert

    Feb 24, 2006
    10,148
    1,791
    You might find it that way, but a faster way to find it is by looking at the compiler output. If the IAR compiler won't allow you to turn on an output listing and/or a linker map then you need to locate the objdump utility which is part of the GNU compiler chain.
     
Loading...