Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have a common pointer between 2 different programs on the same computer

I need 2 different programs to work on a single set of data. I have can set up a network (UDP) connection between them but I want to avoid the transfer of the whole data by any means.

It sounds a little absurd but is it possible to share some kind of pointer between these two programs so that when one updates it the other can simple get the pointer and start using it ??

I am using Ubuntu 9.10

like image 962
user269037 Avatar asked Feb 25 '10 22:02

user269037


People also ask

What happens if you equate two pointers?

Pointer assignment between two pointers makes them point to the same pointee. So the assignment y = x; makes y point to the same pointee as x . Pointer assignment does not touch the pointees. It just changes one pointer to have the same reference as another pointer.

How do you make a pointer point into something?

You need to initialize a pointer by assigning it a valid address. This is normally done via the address-of operator (&). The address-of operator (&) operates on a variable, and returns the address of the variable. For example, if number is an int variable, &number returns the address of the variable number.

Can we assign a pointer variable to another pointer variable?

A pointer is associated with a type (of the value it points to), which is specified during declaration. A pointer can only hold an address of the declared type; it cannot hold an address of a different type. Notes: The address values that you get are unlikely to be the same as mine.


2 Answers

You're talking about IPC - Interprocess Communication. There are many options.

One is a memory-mapped file. It comes close to doing what you described. It may or may not be the optimal approach for your requirements, though. Read up on IPC to get some depth.

like image 180
Cheeso Avatar answered Sep 21 '22 00:09

Cheeso


What you're looking for is usually called a "shared memory segment", and how you access it is platform-specific.

On POSIX (most Unix/Linux) systems, you use the shm_*() APIs in sys/shm.h.

On Win32, it's done with memory-mapped files, so you'll use CreateFileMapping()/MapViewOfFile() etc.

Not sure about Macs but you can probably use shm_*() there as well.

like image 22
Drew Hall Avatar answered Sep 22 '22 00:09

Drew Hall