1

I'm using Microsoft Visual Studio 2008

When I create a pointer to an object, it will receive a memory address which in my case is an 8 digit hexadecimal number. E.g.: 0x02e97fc0

With 8 hexadecimal digits a computer can address 4GB of memory. I've got 8GB of memory in my computer:

  1. Does that mean that my IDE is not using more than 4GBs out of my memory?

  2. Is the IDE able to address only the first 4GB of my memory or any 4GB out of the 8GBs not used?

The question is not only about the size of the memory used. It is also about the location of the memory used. Latter hasn't been detailed here: The maximum amount of memory any single process on Windows can address

Community
  • 1
  • 1
Attis
  • 573
  • 1
  • 7
  • 19
  • leading 0's are often dropped as they do not change the value. – NathanOliver Jan 30 '17 at 12:49
  • 2
    Compiling for 64-bit target will grant you 64bit pointers as well, enabling to address more memory space. – Steeve Jan 30 '17 at 12:50
  • Possible duplicate of [The maximum amount of memory any single process on Windows can address](http://stackoverflow.com/questions/11891593/the-maximum-amount-of-memory-any-single-process-on-windows-can-address) – Alex K. Jan 30 '17 at 12:51
  • 1
    "my IDE" - that's an _Integrated Development Environment_. The editor part of the IDE doesn't care that much; it's the compiler part which decides to use 32 bits. The linker follows the compiler. – MSalters Jan 30 '17 at 15:39

1 Answers1

6

Where does C++ create stack and heap in memory?

Well, C++ does not really handle memory, it ask the operating system to do so. When a binary object (.exe, .dll, .so ...) is loaded into memory, this is the OS which allocate memory for the stack. When you dynamically allocate memory with new, you're asking the OS for some space in the heap.

1) Does that mean that my IDE is not using more than 4GBs out of my memory?

No, not really. In fact, modern OS like Windows use what is called virtual address space. It maps an apparently contiguous memory segment (say 0x1000 to 0xffff) to a segment of virtual space just for your program; you have absolutely no guarantee over where your objects really lie in memory. When an address is dereferenced, the OS do some magic and let your program access the physical address in memory.

Diagram of relationship between the virtual and physical address spaces.

Having 32 bits addresses means a single instance of your program can't use more that 4GB of memory. Two instances of your same program can, since the OS can allocate two different segments of physical address inside the apparently same segment of virtual address (0x00000000 to 0xffffffff). And Windows will allocate yet more overlapping address spaces for its own processes.

2) Is the IDE able to address only the first 4GB of my memory or any 4GB out of the 8GBs not used?

Any. Even non-contiguous memory, even disk memory ... no one can tell.

Found some Microsoft source in the comments about it: https://msdn.microsoft.com/en-us/library/aa366778.aspx

YSC
  • 38,212
  • 9
  • 96
  • 149
  • Does that also mean, that when I'm retrieving the address of an object I'm getting only the virtual address, and not the physical address? (Otherwise I could break parts of other programs.) – Attis Jan 31 '17 at 16:06
  • 1
    Yes, you're only dealing with virtual addresses. This is not only to protect processes against one another, but also to let the operating system handle physical memory more efficiently. – YSC Feb 01 '17 at 08:37