Message Boards Message Boards

2
|
2873 Views
|
0 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Is WolframLibraryData libData a persistent data structure?

Posted 10 years ago

I am writing some C++ code that I want to call both through LibraryLink and independently from Mathematica. Thus it must be compatible with LibraryLink but not depend on it.

When calling it from Mathematica, I want to make it abortable.

All LibraryLink functions take an argument WolframLibraryData libData (this is really a pointer). AbortQ is called through it.

Question: Is it safe to cache the value of libData in a global variable, never change it after WolframLibrary_initialize, and use this global variable for calling all LibraryLink functions?

To make the question clearer, this is the layout of my code:

<!-- language: lang-cpp -->
WolframLibraryData libData; // global variable

EXTERN_C DLLEXPORT int WolframLibrary_initialize(WolframLibraryData iLibData) {
    libData = iLibData;
    return LIBRARY_NO_ERROR;
}

class MyClass 
{
public:
    void simulate() {
        for (...) { // long loop
            ...
#ifdef WolframLibraryVersion  // use the global libData here:
            if (libData->AbortQ) { /* abort computation */ }
#endif
        }
    }
}

Cross posted to Mathematica.SE.

POSTED BY: Szabolcs Horvát
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract