Order of Memory Locations

This is a discussion on Order of Memory Locations within the Linux Programming forums, part of the Platform Specific Boards category; Hello All, I have the following Memory addresses . Address of function f1 :80483a0 f2 :80483e8 main :80483ff Address of ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Location
    India
    Posts
    113

    Order of Memory Locations

    Hello All,

    I have the following Memory addresses .

    Address of function
    f1 :80483a0
    f2 :80483e8
    main :80483ff

    Address of all the local variables in main
    uila :bfedb4d4
    ila :bfedb4d0
    uisl :80498c8
    isl :80498c0

    Iam in a linux environment.

    I want to know what would be increasing order ( memory locations).

    To put in a simple words , i want to know how the OS gives memory locations ( address) to C / C++ programs ?

    Will it vary with the 16 bit , 32 bit , 64 bit computers ?

    Will this depends on the RAM of our computer ?

    Does this depend on the OS we use ?

    regards
    vlrk

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    This is so totally something you shouldn't care about.


    But for the record:
    1) The stack (local variables) is placed at some high address and grows downward.

    2) Program code usually goes to low addresses. The order of the functions is determined by the compiler and linker, except if you use PIE and load address randomization, in which case the program loader shuffles the functions (makes it extremely hard for an attacker to exploit a security hole he's found).

    3) The room in-between is open for various stuff, mainly the heap.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Mar 2008
    Location
    India
    Posts
    113

    What will be increasing order ?

    Thanks for your reply

    I would like to know the increasing order of memory locations?


    Address of function
    f1 :80483a0
    f2 :80483e8

    In above case does a0 is the first one or e8 is the first one.

    i want to know the offset of the memory locations .

    If iam not wrong these fuctions comes into Text/Code section of the exectutable , when it loaded into memory.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    It's a hexadecimal number system. Learn it and you'll know the answer.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Mar 2008
    Location
    India
    Posts
    113

    Differenence in the Local and Heap Memory locations?

    Why there is difference in the heap , static and local memory locations.

    If we observer the below memory locations it shows that functions, static memory variables , global variable and heap meomory variables are of only 7 digits where as local variables are of 8 digits


    Code:
    Output 
    
    Address of function f1:80483a0, f2:80483e8 and main :80483ff
    
    Address of all the local variables in main
     uila  :bffdf8e4, ila :bffdf8e0 uisl :80498c8 isl:80498c0
    
    Address of all the global variables in main
    uig1:80498cc ig1:80498b4
    uig2:80498d4 ig2:80498b8
    uig3:80498d0 ig3:80498bc
    
     Address of dynamically allocated memory : 916c008
    Addresses of all the local and parameter variables of f1
    Addresses of parameter variables pa:bffdf8c0 pb:bffdf8c4
    Addresses of local variables x:bffdf8b4 y:bffdf8b0
    Addresses of all the local and parameter variables of f1
    Addresses of parameter variables pa:bffdf8b0 pb:bffdf8b4
    Addresses of local variables x:bffdf8a4 y:bffdf8a0
    Addresses of all the local and parameter variables of f1
    Addresses of parameter variables pa:bffdf8c0 pb:bffdf8c4
    Addresses of local variables x:bffdf8b4 y:bffdf8b0

    is it any thing related to the 32 bit or 64 bit computers?

    How to know does our system is of 32 bit or 62 bit based ?

  6. #6
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > How to know does our system is of 32 bit or 62 bit based ?
    Query the CPU for information (there are specific instructions. Don't ask how to do this, it's long and CPU specific -- research it yourself.), the OS will know if it's 64bit or not. Pretty much it only matters what the word size of the OS is (ie if it's 32bit and you have a 64bit CPU it doesn't matter, you'll be working in 32 bit).

    > If we observer the below memory locations it shows that functions, static memory variables , global
    > variable and heap meomory variables are of only 7 digits where as local variables are of 8 digits
    This will be impossible to understand without knowing how hex works (hence binary). Again, learn it and you'll know the answer.

  7. #7
    Registered User
    Join Date
    Mar 2008
    Location
    India
    Posts
    113

    Memory Location Addresses , a hint to 32bit/64 bit computer ..?

    I think even this addressing helps in knowing the 32 bit / 64 bit ..?

    i feel so because at any point of time there will 8 hexa decmial bits and in binary every

    hexa decimal bit is equal to four bits so 4 * 8 = 32 bits.

    Am i right or wrong ?

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Digit, not bit. Bit is short for "binary digit", so "hexadecimal bit" is an oxymoron.

    And I have no idea what you tried to say in your last post.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    Registered User
    Join Date
    Mar 2008
    Location
    India
    Posts
    113
    I was just continueing the same topic .. I was refering to the address of the variables.

    I should have given a bit preamble in my previous post.

    One of programas variable address is as like below

    Code:
    uig1:080498cc

    Any hexa digit is of 4 binary bits so i feel here 8 hexa digits ( each 4 binary bits )

    i.e 32 binary bits.

    I think even this would be helpfull in knowing , whether our system is of 32 bits / 64 bits.


    If iam wrong please correct me.

  10. #10
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Just because 64 bits are available, it doesn't mean any of the upper 32 bits are necessarily set. If they aren't, the output may well strip those leading zeros, and you end up with less than 16 digits after all. (That's why some of the addresses above have only 7 digits, after all.)

    What's all this about, anyway? There are far easier ways of finding out the word size of the system than looking at addresses. For example, print the result of sizeof(void*), and you get the machine's pointer size. It's 4 for 32-bit and 8 for 64-bit machines.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  11. #11
    Registered User
    Join Date
    Mar 2008
    Location
    India
    Posts
    113
    Thanks for your insights.

    Any way i was trying to understand , in c program how memory will be alloted by OS.

    I was printing different kind of variable including the function names to understand this.

    My primary idea is not of knowing 32bit etc..

    regards
    Rama Kanth

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,031
    32-bit/64-bit will change the size of the addresses, but you must still note that any leading 0s are usually trailed.
    Learn more about hex to understand more of your output.
    sizeof(void*) will give 4 on 32-bit and 8 on 64-bit (typically).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory Order in Classes
    By skewray in forum C++ Programming
    Replies: 13
    Last Post: 12-14-2006, 06:40 AM
  2. Pointers as array, copying to memory locations help
    By shdwsclan in forum C Programming
    Replies: 1
    Last Post: 04-18-2006, 03:10 PM
  3. Pointer's
    By xlordt in forum C Programming
    Replies: 13
    Last Post: 10-14-2003, 03:15 PM
  4. Managing shared memory lookups
    By clancyPC in forum Linux Programming
    Replies: 0
    Last Post: 10-08-2003, 05:44 AM
  5. Accessing Video Memory Information...need help
    By KneeLess in forum C++ Programming
    Replies: 8
    Last Post: 08-24-2003, 04:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21