I am Building A program with C as the ui and the main process and python at its backend. I want to pass the variables/String from C program to Python A simple File on Hard Drive can be used but it would be better if the ram is utilised to get live change in variables. what can i do. I dont want to use any sockets or pipes. I want to give direct access from the ram.
Asked
Active
Viewed 94 times
0
-
Sockets or pipes are going to be more standard across operating systems than any kind of shared memory solution. And due to the nature of Python's memory model, you'll need to copy values into and out of shared memory to so anything useful with them even if you had them. So I actually think a local socket will be just as fast and likely much, much easier to get working correctly. – Daniel Pryden Nov 24 '18 at 12:10
-
Sockets will need host ip etc. I want to do it on one computer only without any connections – Shantanu vidwans Nov 24 '18 at 12:30
-
No, there's no need for a remote system. You can use the loopback adapter to make TCP connections between processes on a single computer. On a Unix or Unix-like system, you can also use a domain socket, which is basically just a special kind of file in the local filesystem. – Daniel Pryden Nov 24 '18 at 12:57
-
And a pipe is even simpler. Just launch a child process with `popen` and you can communicate back and forth using just stdin/stdout. – Daniel Pryden Nov 24 '18 at 13:00
2 Answers
0
I think you'll be interested in IPC with mmap
and locks.
See docs and for example, here
and maybe here for a code example (with two Python processes only).

progmatico
- 4,714
- 1
- 16
- 27
0
Generally using APIs is the best way to communicate between services in different languages. But if you must have one codebase with shared ram, there is actually something for that with C/Python. It's called Cython: https://cython.org/

Neil
- 3,020
- 4
- 25
- 48