Thread: How Do You Analyze C Memory Layout?

  1. #1
    Registered User
    Join Date
    Oct 2022
    Posts
    92

    How Do You Analyze C Memory Layout?

    Hi everyone,

    I'm learning about how computer memory works in C programming. Can you share how you figure out where things go in memory when you write C code?

    What tools or methods do you use to understand this?

    Thanks for your help!

  2. #2
    Registered User
    Join Date
    Sep 2020
    Posts
    425
    Quote Originally Posted by Kittu20 View Post
    Hi everyone,

    I'm learning about how computer memory works in C programming. Can you share how you figure out where things go in memory when you write C code?

    What tools or methods do you use to understand this?

    Thanks for your help!
    Assuming you want to know the truth, and not just the first-level approximation...

    On Linux you can use the 'objdump' command to see what the C compiler has generated - what goes where in memory.

    But that's not the final word. It also pays to know how linker scripts work, as they combine the object files to make the executable, by combining segments and resolving address references. 'ld' has an option that prints the default linker script to stout, allowing you to investigate it. Have a look at the 'man' page for 'ld' to find it.

  3. #3
    Registered User
    Join Date
    Oct 2022
    Posts
    92
    Quote Originally Posted by hamster_nz View Post

    On Linux you can use the 'objdump' command to see what the C compiler has generated - what goes where in memory.

    .
    This command provides detailed information about of different sections like .text, .data, and .bss.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory layout of c program
    By sujji in forum C Programming
    Replies: 3
    Last Post: 10-15-2013, 12:08 AM
  2. memory layout??
    By ungainly_one in forum C Programming
    Replies: 14
    Last Post: 11-14-2010, 10:12 AM
  3. memory layout problem
    By iamnew in forum C Programming
    Replies: 5
    Last Post: 06-05-2010, 08:48 AM
  4. Memory Layout
    By chris.r in forum C Programming
    Replies: 5
    Last Post: 04-18-2010, 02:41 PM
  5. memory layout and declaration
    By cbastard in forum C Programming
    Replies: 6
    Last Post: 09-13-2005, 12:24 PM

Tags for this Thread