I've been having some thought, like, if I run a program, and I'm exporting a pointer to a variable "a" to a file, and I reads that information with another program, wouldn't the second program be able to modify "a" in the first program using that pointer? - Like the memory address is the same right?

And then I need some help, is it possible, for me, to write some code lines in a text file, and like make the program load and execute these lines from the file? - if I got a program, and I need to do a lot of testing in a specific sector or something, is it possible? - I know it's possible with shaders.

Dani AI

Generated

raised two useful questions (pointer-exporting and runtime-loading of code) and pointed in the right direction: an address value is only meaningful inside the process that owns that virtual address space. The OS gives each process its own virtual address space via page tables, so writing a raw pointer value to a file and reading it in another program will not reliably let the second program access the same object. Dereferencing that numeric value will usually fault or hit unrelated memory.

There are safe, supported ways to share data between processes and other ways to run code from text at runtime:

  • Shared memory / memory-mapped files: create a named mapping and map it into both processes; this is the canonical approach for sharing live data (Windows: memory-mapped files, POSIX: shm_open + mmap). See Windows memory-mapped files () and POSIX shm_open (https://man7.org/linux/man-pages/man3/shm_open.3.html).
  • Standard IPC: pipes, sockets, files, RPC — simpler but involve copying rather than direct shared memory.
  • Remote process memory access: debuggers can read/write another process (OpenProcess / WriteProcessMemory on Windows, ptrace on Unix) but this requires privileges and is unsafe for production (https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-writeprocessmemory).
  • For runtime code execution: embed a scripting language (Lua, Python, JavaScript), load compiled plugins (shared libraries), or use a JIT compiler. Embedding is usually the easiest for rapid testing and avoids the risks of compiling and injecting native code (see embedding Python: https://docs.python.org/3/extending/embedding.html).

Notes and cautions: shared memory needs explicit synchronization (mutexes/semaphores), agreed data layout, and attention to security (never run untrusted code or allow arbitrary memory writes). For a quick experiment to share a single variable, a named memory-mapped region plus a named mutex is the simplest and safest route.

Recommended Answers

All 3 Replies

I've been having some thought, like, if I run a program, and I'm exporting a pointer to a variable "a" to a file, and I reads that information with another program, wouldn't the second program be able to modify "a" in the first program using that pointer? - Like the memory address is the same right?

Any addresses you obtain are not real addresses but rather virtual addresses. In terms of real hardware addresses, i.e., physical addresses, only Windows itself deals with them. It isn't like back in the old DOS world where you could actually deal with hardware.

There are ways to share data between processes, but writing a virtual address to a file and reading it with another program isn't one of them.

Any addresses you obtain are not real addresses but rather virtual addresses. In terms of real hardware addresses, i.e., physical addresses, only Windows itself deals with them. It isn't like back in the old DOS world where you could actually deal with hardware.

There are ways to share data between processes, but writing a virtual address to a file and reading it with another program isn't one of them.

So you're saying that I'm unable to use my pointer in another program, even tho it isn't released by the main program yet (still running). - Like, what would that pointer, point to then? - if I call it's value in the second program.

And I know that there are ways, it was just 'Some thoughts'.

Like, what would that pointer, point to then? - if I call it's value in the second program.

More than likely some address not valid in the second program. If you want to try it go ahead - it shouldn't be that hard to do. I'm telling you what I am from my study of these things, plus I've seen this topic come up occasionally in other forums. If somebody else knows better, please jump in and correct me. My understanding of this issue is that Windows completely virtualizes hardware, and only within the deepest recesses (and not available to us) of the kernel is the actual mapping of the various processes's virtual addresses to physical hardware addresses.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.