Modern operating system use "protected mode", which means that each process has its own separate (virtual) memory space. This memory space is 4 TB in size for 32-Bit processes. For 64-Bit processes, it is even 16 Exabytes in size 😲
But: Just because those (virtual) memory addresses "exist" in your process' memory space, it does
not mean that they all are actually mapped to anything! For example, if you sum up the total sizes of the individual (virtual) memory spaces of all the processes that are running on your machine, then this will be
way bigger than what actually fits into your (physical) RAM. However, that is perfectly okay, because most of those virtual addresses simply are
not mapped to physical addresses in the RAM, or to anything else.
Simply put, some memory addresses are allocated "statically" when your program is starting up (e.g.
global variables). Additional memory addresses may be allocated "dynamically" at runtime, e.g. by using
malloc()
or similar functions. And then there is the "stack", which is used to hold the
local variables of the current function. But, any memory address that has
not been "allocated" before, in one way or another, must be considered "invalid" (inaccessible). Any attempt of trying to access such an "invalid" memory address results in an
access violation (segmentation fault) hardware exception – which usually causes your program to terminate abnormally ("crash").
Therefore, trying to access some arbitrarily chosen address, e.g.
0x1317CFFC14
, is likely to crash your program with an "access violation" error, because there is
nothing that would guarantee that this particular address is valid (and that it is writable) within your process memory space! If fact, with such an arbitrarily chosen address, chances are extremely high that the address happens to
not be valid 😨
Also, because of things like
ASLR, the memory layout of your program may be different on each execution:
https://en.wikipedia.org/wiki/Address_space_layout_randomization
Last but not least, you can
not access the memory of
another process, because the (virtual) memory spaces of each process is totally separate from other processes. The very same address that is valid in one process can have a completely different meaning, or can be "invalid", in the other process. If processes want to share data via the memory, you explicitly have to create a "shared memory" segment
and then each of the processes needs to map that "shared memory" into its own address space. Here is a tutorial for Windows:
https://learn.microsoft.com/en-us/windows/win32/memory/creating-named-shared-memory
(If you think of virtual memory addresses as telephone numbers, then the "space" of possible telephone numbers is
huge, but most of those numbers have
not been assigned to customers yet. Trying to call an "unassigned" number will give you a "this number is currently unavailable" announcement. The
access violation is the operating system's way of telling you that you called an unassigned number 😏)