Why does this work?

BlitzMax Forums/BlitzMax Programming/Why does this work?

In Windows at least, every process has it's own address space. This is accomplished by virtual memory, every process can (theoretically) use all 4gb of addressable memory (in a 32bit system). The windows memory manager handles the mapping of the virtual addresses to physical addresses as and when those memory addresses are required to be accessed. (using the swap file)

That said, in your diagram the red blocks wouldn't exist (because every process has no knowledge of the virtual addresses allocated by another process, nor does it care).

It is correct to say that some memory is allocated to your process (the exe itself and all it's data areas are mapped in), the process itself has thread storage areas, it's own process heap, and dynamically allocated memory etc etc.

To answer your question, any memory *allocated* to your application can be accessed (in your case, the exe contains a data section containing the emptyarray which is simply mapped into virtual memory - ie allocated to your process).

If you read/write to any unallocated area, or write to an allocated but readonly area you will get an access violation.