Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Using MappedByteBuffer for shared memory  (Read 1441 times)
0 Members and 1 Guest are viewing this topic.
Offline Brian

Junior Newbie




Java games rock!


« Posted 2004-11-19 17:34:56 »

I read in Practical Game Programming in Java that MappedByteBuffers could be used for passing data between processes.  If I wanted to use such a buffer to pass data between processes, what's a good way of notifying the other process that there's new data to be read from the buffer?

Brian
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #1 - Posted 2004-11-19 17:52:23 »

This article (scroll down to "Memory-Mapped Files") explains the situation fairly well. Bascially, using Mapped files for RPC is not guaranteed functionality, and thus is not recommended. You also don't know what kind of delay there might be between updates of the memory block (for systems where the block is not identical memory locations).

None the less, your problem can be solved with polling. The exact way to handle things depends upon what you want to do. i.e. Are you using a server to push to a set of client processes, or are you attempting back and forth communication?

With the former case, you could have a four byte header (an int) at the top of the block, with a packet counter. If the packet counter increases, your program knows that the data has changed. If you need the writes to be synchronous, you can use an extra byte per process as an "ACKnowledge" flag. When the server process writes the data, it sets the ACK flag to 0. After the receiving process is done reading, it sets the flag to 1.

A similar approach can be taken in the later case. Instead of using one block, however, I recommend that you make use of two blocks. Each process with the server of one block and the client of the other.

Does that help?

Edit: RPC should be IPC. RPC wouldn't work very well this way. Wink

Java Game Console Project
Last Journal Entry: 12/17/04
Offline Brian

Junior Newbie




Java games rock!


« Reply #2 - Posted 2004-11-19 17:54:49 »

Helps alot -- thanks much!  Brian
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (14 views)
2014-09-19 03:14:18

Dwinin (32 views)
2014-09-12 09:08:26

Norakomi (58 views)
2014-09-10 13:57:51

TehJavaDev (80 views)
2014-09-10 06:39:09

Tekkerue (40 views)
2014-09-09 02:24:56

mitcheeb (62 views)
2014-09-08 06:06:29

BurntPizza (46 views)
2014-09-07 01:13:42

Longarmx (31 views)
2014-09-07 01:12:14

Longarmx (37 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!