Re: MathLink function: Global variable?
- Subject: [mg3217] Re: [mg3170] MathLink function: Global variable?
- From: jfultz (John Fultz)
- Date: 18 Feb 1996 00:22:24 -0600
- Approved: email@example.com
- Distribution: local
- Newsgroups: wri.mathgroup
- Organization: Wolfram Research, Inc.
- Sender: daemon at wri.com
> HI. I am writing a C function with Mathlink. > I have noticed that global variable stays there after each execution of the > function after Install. > Is this what it supposed to be? > Is this means that I can keeps some context in C function during Mathematica > session? > > --- > Chang Song (song at cs.purdue.edu) The short answer is yes. The long answer, which I hope will help you to understand installable functions a bit better, is to tell you exactly how installable functions execute. Note that, when you run an installable function, the function called is MLMain(). MLMain() is a function created by mprep (or SAmprep if you're on a Mac) that does the following in a continuous loop: * Wait to receive information from Mathematica * Reformat the received information and pass it off to the appropriate user-written function * Receive results from the user-written function, reformat it, and send it over the link back to Mathematica. * Wait to receive information from Mathematica again This is a pretty simplified view of it, but it's essentially how it works. Note that the program never quits--it continues executing forever and ever, until it is notified that it should Uninstall itself. So, there is no opportunity for global variables to ever be reset, since the program itself is never reset. Sincerely, John Fultz jfultz at wolfram.com Applications Group Wolfram Research, Inc.