Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SHARED MEMORY

Status
Not open for further replies.

wezmac

Programmer
Dec 3, 2003
1
IE
Hi,
Im working on a program at the moment, using shared memory between 2 applications. I know how to initialise and attach shared memory etc. Im stuck on trying to pass it between applications. Its a game, both applications are different players. Each time a player takes a go, it must be shown to the other player. then that player gets his go etc.
 
Perhaps you could be more specific about the problem that you are having. What is your OS, Windows? *nix? Maybe you could post some code showing the problem.

> Im stuck on trying to pass it between applications.

What do you mean by "it"? Are you having trouble knowing how to assign both apps the same shared memory segment, are you not able to read/write the shared memory, is it a problem of synchronization between the apps or something else?

With more info, maybe someone can help.
 
Hi,
typically when you allocate a shared memory segment it will be assigned a SHMID. You must record that SHMID some place that both applications can read it when it starts up and attach to it.

Another alternative is to use your own SHMID when you create the segment. Something not ordinary and out of the way. like your birthday '20031116' or some big number '0xdeaddead'

How many people would every access a Shared memory segment by that name?

By using a WELL KNOWN SHMID the applications can HARD CODE the SHMID and always use it to access the segment.

once both applications are attached to the shared memory segment you use a coordination field or a semaphore or soemthing to tell each player who's turn it is.
 
>How many people would every access a Shared memory segment by that name?

Anybody else who has a birthday on the same day?

Risky, very risky.
 
Under *nix OS, the SHMID is generally generated by first using ftok() to generate a unique key. If the problem that wezmac is having relates to the SHMID, then ftok is the way to solve it. By being careful about the pathname being passed to ftok, a unique key and shared memory id is guaranteed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top