How a computer ensures that a location in RAM is empty
In a multitasking system, every process receives its own virtual address space, i.e. the system maps the addresses from $0_h$ to $FFF\cdots F_h$ to available storage space which can reside partly in RAM memory and partly on disk (physical storage). The mapping is made for every process independently, allocating whole pages (typically 2K bytes) at a time.

The compiler is completely unaware of where the data will actually be stored and is free to use the whole address space. The system does the necessary housekeeping and ensures that there are no conflicts.

Actually, the mapping is completely dynamic and pages are moved between RAM and disk, following the needs of the processes and in a way to optimize the access speed. There is not even a relation between the size of the virtual address space and the amount of RAM and disk available.

To summarize, memory allocation is transparent to the compiler, as if the process was alone; only the system knowns which physical pages are free or allocated to a particular process.