+7  A: 

The short answer is that different processes use completely different address spaces. Without doing a lot more work, process B can't read or write the memory from process A.

It is possible to do this, in a platform-specific way. Win32 offers functions such as WriteProcessMemory where you can directly poke values into the memory space of another process. Most operating systems offer a shared memory function, with Win32 you can use memory mapped files and Unix flavours typically have some kind of equivalent "mmap" or "shmem" feature.

Greg Hewgill
+2  A: 

Hi

I think that most operating systems are designed to make it impossible (or very difficult) to do what you are trying to do -- have one running program (or process) interfere with the contents of the address space of another running program (or process). Since you don't tell us your platform it's difficult to be categorical about this, but I suspect that the o/s is saving you from yourself. This rigid separation of processes is a safety feature on single-user machines, a safety and security feature on multi-user machines.

There are, of course, many techniques for running concurrent processes which can share memory or which exchange information by message-passing. Take some more time off school and study those !

Regards

Mark

High Performance Mark
@Mark - This topic interests me. Could you give me an example of some techniques used to 'share memory' or 'exchange information by message-passing'? Thanks!
acron
Sure, Google around for 'shared-memory programming', for 'concurrent programming', 'message-passing programming'. Wikipedia might be a good place to start.
High Performance Mark
+1  A: 

Take a look at either Memory Mapped Files or Shared Memory.

http://msdn.microsoft.com/en-us/library/aa366551(VS.85).aspx

Computer Guru