Hello

Ripened such a question, pondered for a long time, sort of articulated. As in any language, to output a variable to any other language, i.e. so that any other application can handle it?

Approximately implementation I represent such:

  1. We take the address of the variable
  2. We take the length in bytes
  3. Pass them on to the process.
  4. We are waiting for changes
  5. We continue work

The tags indicate the languages ​​that I will be able to check myself in the near future, as well as any. Axis - Windows (if you are interested in lin, create plz a separate topic, because I can not check)

The condition is not to use pipes, sockets, etc. (unless to transfer the address and length). Why - well, for example, because transferring a 200-meter array through a local socket may take longer than processing it in an assembler. There is likely to be adequate to write to the file of two long int, because This is the easiest and most stable for any language - write and retrieve from a file. Accordingly, consider that the application may not have access to this memory area and provide it.

Stock for delphi (not aware of whether the variable will be available):

var myVar: String; varLink: Cardinal; varLength: Cardinal; ... myVar := '0lol'; // myVar[1] - статус varLink := Cardinal(Addr(myVar)); varLength := Cardinal(Length(myVar)); makeCommonVar(varLink, varLength); // собственно, оно while myVar[1] = '0' do // пока в статусе ноль, отдыхаем begin Sleep(50); Application.ProcessMessages; end; ShowMessage(myVar); // показываем переменную 

Perhaps muddled ... Something like "let's write bridges between all languages." You can recall the well-known ArtMoney majority - the principle of work is somewhere nearby.

Yes, php is there in the labels separately - I do not even know if it is possible (and how) to get the address (int) of a variable.

If the code does not threaten to be huge - examples are welcome. Why is this all? Well, for example, different languages ​​have different tasks and somewhere the processing of a variable can be faster / more convenient / easier, after all.

    4 answers 4

    There are a lot of options, why reinvent the wheel?

    1. mapping files to memory (mappedFiles)
    2. dll
    3. WM_DATA (sort of like the message is called)
    4. Data Base! (:))
    5. memcache (d)

    And most importantly, for what it may need?

    • Here, somewhere from this steppe, I am looking for something) Ideally, pieces of code for several languages ​​are needed so that they can cooperate. For what - well, the closest practical value - is something heavily loaded on the web. An example is trivial - processing a 15-meter sample from a database on php, each time for each request is different. You can be perverted with the cache, optimize, etc., but php will still kill it) And you can connect something assembler. It is for php - this is the most transparent example for the braking language itself, but simply transferring tasks from one language to another is useful. - Sh4dow
    • one
      here on [delphi] [1] [1]: delphifaq.com/faq/delphi_windows_API/f348.shtml - Alex Kapustin

    In short, from this whole stream of consciousness, I realized that you need to figure out how to transfer data from one process to another. And in both processes, programs written in different languages ​​are executed. Let me remind you that each process is executed in its virtual address space of memory, and it cannot simply get access to the space of another process. There are several solutions for sharing data. All of them have long been known and implemented on most modern operating systems. Payps, sockets, signals, message queues. For your purposes, I kaz, the divided memory will approach. This is when a certain area of ​​memory becomes available to both processes. And it does not matter in which language the programs are written, since all these IPCs are implemented at the OS kernel level. The main thing is that this language support this type of IPC or at least give the opportunity to call the API functions of the system. And yet: the data is not transmitted from language to language, from program to program.

    • > any other language, i.e. so that any other application can process it. Maybe it is messy, but the following was meant: the application (the language in which it is written) should have the means (get AND pass) this variable. Can you give an example of such a wrapper for shared memory (dll, for example) that any of at least the listed languages ​​could use as a return or reception ? - Sh4dow
    • If you need something very high-performance, write in C / C ++. Assembler do not touch, if not a masochist. In the languages ​​you specified I am not a very big spec, so google + reference books. - skegg
    • I'm closer to dolphins with asm, well, asm itself - something so dear, from childhood)) Well, I understood approximately, thank you. - Sh4dow

    I would advise to rummage towards COM objects, or DLL

    • I would even prefer a COM object. suitable for any language supporting com - Vladyslav Matviienko

    Yes, it looks like only a DLL or a variable to a file, although it is not kosher.