This program uses 1 TiB of virtual address space, and runs fine on a machine with no swap (and much less than 1 TiB of physical RAM).
#include <sys/mman.h>
#include <stdlib.h>
int main()
{
size_t const len = 1024 * 1024 * 1024; // 1 GB
for (int i = 0; i < 1024; ++i) {
char *p = (char *)mmap(0, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON,
-1, 0);
if (p == -1) exit(-1);
}
}
The space won't be associated with any physical object (whether RAM or swap) until you actually touch it.