Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest way to do local IPC between a Unity process and another C# process [closed]

Tags:

c#

unity3d

ipc

I want to deliver a huge amount of data around 30 times each second from a C# application to my Unity Application. Since mapped memory and pipes aren't supported in Unity i thought about a tcp socket. Would this be fast enough if the communication is in the scope of one machine only?

like image 316
lassedev Avatar asked Sep 17 '15 14:09

lassedev


People also ask

Which model of inter process communication is faster?

Shared memory is the fastest form of interprocess communication. The main advantage of shared memory is that the copying of message data is eliminated. The usual mechanism for synchronizing shared memory access is semaphores.

What is the lowest latency method for interprocess communication?

Our experiments re- veal that shared memory provides the lowest latency and highest throughput, followed by kernel pipes and lastly, TCP/IP sockets.

How do you communicate between processes?

Two-way communication between processes can be achieved by using two pipes in opposite "directions". A pipe that is treated like a file. Instead of using standard input and output as with an anonymous pipe, processes write to and read from a named pipe, as if it were a regular file.

Can you code in C in Unity?

The language that's used in Unity is called C# (pronounced C-sharp). All the languages that Unity operates with are object-oriented scripting languages. Like any language, scripting languages have syntax, or parts of speech, and the primary parts are called variables, functions, and classes.


1 Answers


Possibly as of 2017, Unity also supports Managed plug-ins.


Unity3D supports c++ too.

Native plugins are platform-specific native code libraries. They can access features like OS calls and third-party code libraries that would otherwise not be available to Unity. However, these libraries are not accessible to Unity’s tools in the way that managed libraries are. For example, if you forget to add a managed plugin file to the project, you will get standard compiler error messages. If you do the same with a native plugin, you will only see an error report when you try to run the project. More...

...and:

Unity has extensive support for native Plugins, which are libraries of native code written in C, C++, Objective-C, etc. Plugins allow your game code (written in Javascript or C#) to call functions from these libraries. This feature allows Unity to integrate with middleware libraries or existing C/C++ game code. More....

With c++ code you are free to do anything you want including writing a native name pipe server through which your c# app could send data to.

Local named pipes are incredibly fast because they run in Kernel mode and don't go through the network layer unlike TCP which does.

I would recommend named pipes over TCP if comms is for local machine only.

Alternatives

Alternatives to named pipes are:

  • COM
  • DDE
  • File mapping (including shared memory, thanks Ben!)
  • Mailslots

Tell me more...

like image 187
MickyD Avatar answered Sep 30 '22 00:09

MickyD