Why are these values seemingly so random? It's all virtual anyway, so why not just give me address 4096 to start us off?
without specifying the operating system and architecture of your system, it's not possible to say. But as somebody has pointed out, the malloc
library tries to take advantage (and for security reasons too) by acquiring memory segments spread enough in the full 64bit virtual address space of your computer (that is, indeed, huge) This will allow a malicious process that, for some reason has access to your virtual space, to have almost no probability of guessing where in memory your data is. But as a side effect, you get all those big numbers. You don't tell if you are in such a 64bit cpu, but it's common in linux, to have this spread of memory segments to allow for big holes of unused memory in its virtual address space, interspersed with small used segments. Also, the probability of a stack collision with a memory segment is low (while this is checked anyway by other means) or the grow of a data segment to overlap another segment to be impossible.