cmemory-addressmemory-size

lowest and highest memory address in c?


Is there a way to print out the lowest and highest memory address that an Operating System can address in C?


Solution

  • No, this is not a feature of standard C. Whatever solution you need will need to be OS-specific.

    If you have some specific OS' in mind, you should mention them. But I'm having a hard time wondering why this would matter. It's not required to be able to write C programs, so perhaps you could enlighten us.

    Based on your comment:

    What I'm curious is "if each process gets an address space in memory, can I be able to print out the top-address and bottom-address of that process?"

    Again this depends on the OS. Your address space is not necessarily the physical memory you have, it's the totality of the locations you can address. For example, an operating system based on x86 may give every single process its own 4G address space but you have to ask the OS for "backing" memory (actual real memory to put in that address space).

    And some of that address space is actually shared amongst all processes (where the OS can load one physical copy of its code for the use of all processes, for example).

    You have to remember that virtual memory and physical memory are very different beasts.