Reputation: 623
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:
Does that mean that my IDE is not using more than 4GBs out of my memory?
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
Upvotes: 1
Views: 830
Reputation: 40060
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.
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
Upvotes: 6