简体   繁体   中英

Program address range

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!

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).

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.

有关Windows操作系统中虚拟地址空间的更多信息: http : //www.tenouk.com/WinVirtualAddressSpace.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM