c++ - What is the defacto standard for sharing variables between programs in different languages? -


I have never done formal training in this area, so I wonder what they read in school (if they do ). Say that you have two programs written in two different languages: C ++ and Python or some other combination and you want to share the continuously updated variables on the same machine, what would you use and why? The information should not be safe, but should be authentic should be isocronous.

The example A program will get a value from the hardware device and the variable x will update every 0.1ms, so I will be able to get this X from Program X to be able to get the latest values. . Program A and B are written in two different (strong) languages ​​and compiled. How do I use the program B to X? Suppose I have a source code from A and B. And I do not want to completely rewrite or do not want to port any of them.

I have used this method so far, including:

  • File Buffer - Read and write a file (like C: \ temp.txt).
  • Create a cover - from A to B or B to A.
  • Memory buffer - Specify a specific memory address (mute x?).
  • UDP packets through sockets - have not tried it yet but looks good firewall?

    Just sorry to throw it out, I do not know what the name of this technique is, so I have trouble.

    Thanks in advance, -Ee student.

    When you ask specific questions, you should provide as much information as possible. You have added a usage case, but the use case is incomplete.

    The case of your special use looks like very small amounts of data which should be available at high frequency 10kHz. First of all, I try to determine if I can actually split the code part of the same process, depending on the language ( missing from the question ) instead of two different processes ) It may also be simple, or possibly impossible - depending on the OS ( anonymous by question ), the scheduler can not swiftly switch from one process to another, and it will be Read the availability of the latest The effect of switching between threads is usually very fast.

    If you can not change them in the same process, then you have to make less use of IPC (Inter Process Communication). Due to frequency, I will exclude the most weighted protocols (Avoid XML, Corba) because the overhead is probably too much if the need to reach the latest value at the end of receiving, and this entry may be less than 0.1 ms , Then you do not want to use any protocol that contains the queing because you care about the last in the next element queue, If you could not read the element when it was good, avoid the cost of processing it, when it is already stale, it does not mean to remove the loop by removing it from the queue.

    I will be tilted to use a shared memory or memory mapped file (they are probably quite similar, depending on the platform missing from the question ) the size of the element and Depending on the exact hardware structure ( anonymous by question ), you may be able to avoid locking with Mute X. As an example in the current Intel processor, access to read / write access to 32bit integers is guaranteed to be atom if the variable is correctly aligned, in that case you will not lock.

Comments