Re: simplified C API call in MathLink
- To: mathgroup at smc.vnet.net
- Subject: [mg55961] Re: simplified C API call in MathLink
- From: "ragfield" <ragfield at gmail.com>
- Date: Tue, 12 Apr 2005 05:26:10 -0400 (EDT)
- References: <d3835t$cej$1@smc.vnet.net><200504101054.GAA29032@smc.vnet.net> <d3cq78$6ek$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On Apr 10, 2005 7:49 PM, Edward Peschko <esp5 at pge.com> wrote: > Just curious, but does the following have state? Does the MLINK remember > what variables were entered into it, so you could print them out later? The MLINK is really just a connection to an instance of the Mathematica Kernel (or any other MathLink program, but it is usually just used for Kernel connections). As long as the MLINK remains open, the Kernel will keep its state. For example, if one evaluated "a=5" followed by "a+2" the result would be 7. > And would you be able to export graphs back to C (using ExportString, per chance)? > Or are there embedded nulls to worry about, and if so, how do you handle them? Absolutely. Non-7-bit-ascii characters are treated specially by MLGetString in that they are escaped like this 0x0 -> \.00, 0xFF -> \.FF 0xAAAA -> \:AAAA. There are other string methods that avoid this. Which string function you use depends on what type of data you expect to be returned. If you did ExportString[..., "GIF"], you would know you were working with binary data, it would be more appropriate to call MLGetByteString, which returns the raw data & the length of that data with no escaping. However, MLGetByteString does not handle Unicode characters > 255. > just curious, but when you have a MLINK instance, does it count > as a separate process instance? I noticed that I cannot have more > than two 'math' processes, without mathematica complaining. Is this > true for MLINK instances? The sample code I provided will launch it's own instance of the Mathematica Kernel. It is possible to connect to an already running kernel (with cooperation from that kernel), but doing this is tricky. One app has to create a named link (via TCP/IP or SharedMemory), and the other side has to connect to it. Then you have to force the kernel to wait for evaluations on multiple links. This is even tricker. I believe the J/Link package has a function ShareKernel[] which does this. Perhaps you could check into what it is doing. -Rob
- References:
- Re: simplified C API call in MathLink
- From: "ragfield" <ragfield@gmail.com>
- Re: simplified C API call in MathLink