João Bastos
João Bastos

Reputation: 193

Ocaml: It there a way to pass objects between processes?

This is a real question.

I am working with named pipes to transmit data between processes/threads, but this data is of type string is is possible to pass and object this way?

Is there anyway to pass an object?

My problem is the following:

I have a thread Missile, and a Process World. World receives the location of the Missile and returns the computation of the new location.

Right now I am doing this by taking information from the string writing in the pipe. Is there a way to pass this as an object or a tuple?

If anyone could help me with this, it would be great! Thanks.

Upvotes: 2

Views: 301

Answers (2)

Alexander Mills
Alexander Mills

Reputation: 100000

Convert objects to JSON? pass the data between processes as JSON strings?

Upvotes: 0

Jeffrey Scofield
Jeffrey Scofield

Reputation: 66818

You can use the Marshal module to pass arbitrary OCaml values through a bytestream. It's tricky to get right, so I'd advise reading the Marshal section of the manual. The main thing is that it only passes values, not types. So your receiving process will need to have a definition for the exact type of the object being passed, and you need to specify the type explicitly in the receiver.

Values that contain functions, which includes OO-style objects, can't be marshalled except between copies of the same program. Maybe this applies to your case (since you mention that you have a thread), but it might be better to use a tuple anyway.

Upvotes: 6

Related Questions