About Object Pointers-Collection of common programming errors
Well, I’ll try to explain better. I wonder how well it will turn out.
Ok, all CRT memory management functions go through the Win32 HeapAlloc function for allocating memory. The Win32 Heap functions or the base CRT functions don’t actually need to be used.
If you go to the lower level memory management functions (the Virtual functions) you can request an actual starting memory address. Because of this, any memory allocator that makes use of this functionality can consistantly allocate memory on the exact same location. (But even using VirtualAlloc to allocate memory can’t guarantee that you will get memory allocated at a certain address, it just gives you a high possibility. If the process heap happens to get allocated on that same address then obviously you can’t allocate it yourself.)
So yes, it is true that for an application using the basic CRT or Windows memory allocators, the memory locations used change between runs. But there are some allocation functions which, if you build on top of, you can override the default functionality and try to force allocations at the same address.
But as I said, this is just Windows. Computers in the past, when there was very little memory to go around, used fixed memory addresses. Consoles generally did too. So there are pleanty of cases where a computer uses fixed memory addresses. This means, as I said, it is an implementation detail of the Windows heap functions and doesn’t mean that all allocators will work like this.
Oh, as a bit of interest, try doing this.
Create a sample program and allocate a few blocks of memory, then look at the addresses used. You should notice that even though they use different base addresses, they are actually at fixed offsets from a base address.