Reputation: 2355
When I write a simple program using C / C++ , what's the address range I get? I mean, I can point to wherever I want.. like :
void* ptr = (int*)0xFFFFFFFF;
Where does that pointer actually point to? I guess its not the real address in the main memory but just the "cover" address of my program.
Can anyone explain that to me? What's the address range I get (in windows for example) when running my own C program? Can I really access other program's address range if I want to?
Thanks!
Upvotes: 0
Views: 997
Reputation: 5168
You CAN'T access another program's memory. The OS keeps them separate. Only possible way is through some formal mechanism like shared memory or some kind of physical memory mapping.
Upvotes: 1
Reputation: 151
More about virtual address space in Windows OS: http://www.tenouk.com/WinVirtualAddressSpace.html
Upvotes: 0
Reputation: 249592
Your program runs in a virtual address space, and pointers point to locations within virtual memory. So no, you cannot expect to conjure up a pointer with the same numeric value as one in another program and have them both point to the same actual memory. On the contrary, if you do that your program will likely crash or otherwise misbehave (but beware: it's undefined behavior, so anything could happen and it's platform-dependent).
Upvotes: 4