   C++ & Java file control
  Quick and short question. Anybody know if a file open will fail in C++ if it is already open in a java program and vice versa, will java fail if already open and not closed in C++?ie have done fopen and not done fclose() yet (pseudo code cant remember the exact syntax.) Im hoping that it WILL fail, because i want to pass information safely from C++ to java to allow some of the advanced features of C++ with the easy threading features of Java. If this is a stupid way to do so (probably is) pls enlighten me. I only need to pass a 2d array of 1's and 0's from c++ to java, and a few integers from java to c++ in response.Stu   
Quote:Original post by stu2000Anybody know if a file open will fail in C++ if it is already open in a java program and vice versa, will java fail if already open and not closed in C++?It depends on OS.Quote:because i want to pass information safely from C++ to java to allow some of the advanced features of C++ with the easy threading features of Java.Unix is built on concept of pipes and files which processes use to communicate with each other. fork()ing is accepted way to spawn new processes and there are ways to hand off file descriptors.So the idea itself is not stupid. The proposed implementation however relies on some obscure behavior which may be problematic - the file system is abused for messaging system, which may or may not work.Quote:I only need to pass a 2d array of 1's and 0's from c++ to java, and a few integers from java to c++ in response.The by far simplest way is to design the slave application as command-line tool. Like 'dir' or 'copy'. Have it accept a file, let it produce a file. Then the master application simply executes the relevant process by passing in temporary file (system() or Runtime.exec()).Quote:with the easy threading features of Java.Java threading is "easy" precisely because it is not C++. As soon as C or C++ native code or OS are mixed in, things are just as tricky as usual.Again, this depends completely on OS, this is how web servers worked, or some still do. Server application accepts sockets, then spawns new process for each connection. Depending on OS, this can be relatively efficient (thousands of processes spawned per second).   ;  IPC using files and pipes is common and can be used to communicate between Java and C++. It all depends on the flags used to open the files and of course the OS.Thats why such code is either written to one platform or tested on several to have the proper combination of flags and other things.BTW, Windows supports pipes just as well as Unix. Take PS3 media server for example. It is written in Java and uses mencoder (and others) to perform transcoding of content. Its open source too so you can always try to see how they've implemented their IPC.;  Under Linux you should use '/dev/shm' to get better performance. See alsoWhat is /dev/shm and its practical usageandWikipedia: tmpfs;Quote:Original post by stu2000i want to pass information safely from C++ to java to allow some of the advanced features of C++ with the easy threading features of Java.Please explain more about what "advanced features" of C++ you are looking for, and what you are hoping to accomplish with threads.   