Thread: Memory layout of C program goes into RAM?

  1. #1
    Registered User
    Join Date
    May 2020
    Posts
    13

    Memory layout of C program goes into RAM?

    Excuse my confusion. I am learning about how C programs are executed in memory. Here is the diagram:
    Memory layout of C program goes into RAM?-selection_006-png

    So, once a C program has been compiled and the executable has been created, the executable gets loaded into RAM? The diagram above, that is the layout of the RAM where the C executable will be stored and executed? Will the size of how many C files you have in a program how much RAM the program takes up?

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,011
    What you are asking is implementation defined for the most part.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    May 2020
    Posts
    13
    Quote Originally Posted by stahta01 View Post
    What you are asking is implementation defined for the most part.

    Tim S.
    Okay, as I've researched, when the executable is created, it gets loaded into RAM, but is the diagram showing how the RAM processes the executable while it runs?

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,011
    Quote Originally Posted by RicsterB View Post
    Okay, as I've researched, when the executable is created, it gets loaded into RAM, but is the diagram showing how the RAM processes the executable while it runs?
    Maybe maybe not! As I have already said it is implementation defined. If a book said that is the way it is always done, throw away that book!
    The CPU and the OS normally defines the way it is done!

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    500
    Quote Originally Posted by RicsterB View Post
    Okay, as I've researched, when the executable is created, it gets loaded into RAM, but is the diagram showing how the RAM processes the executable while it runs?
    A C program needs several memory areas. The executable code itself, the stack, the heap, and global data. Global data is usually then divided into read-only memory, initialised memory, and memory initialised to zero.

    Whilst you might run across a few odd implementations which do things differently, that's pretty standard. The exact layout will vary. On desktop machines, usually pages are marked as "executable" as an anti-virus measure, so the executable code will be on these pages. On a smaller system, there might be no distinction at machine level between executable code and data. Similalry, if the system allows for multiple programs to run concurrently, the heap will usually be shared. If there is only one program running at any one time, the heap and stack probably grow from opposite directions into the same region of memory.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    https://github.com/MalcolmMcLean


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. some questions about memory layout of a c program?
    By sweezy in forum C Programming
    Replies: 2
    Last Post: 11-05-2015, 09:32 AM
  2. Memory layout of c program
    By sujji in forum C Programming
    Replies: 3
    Last Post: 10-15-2013, 12:08 AM
  3. Replies: 14
    Last Post: 10-12-2012, 02:39 AM
  4. memory layout??
    By ungainly_one in forum C Programming
    Replies: 14
    Last Post: 11-14-2010, 10:12 AM
  5. Memory Layout
    By chris.r in forum C Programming
    Replies: 5
    Last Post: 04-18-2010, 02:41 PM

Tags for this Thread