Library Initialization and Cleanup |
Each toolkit in the Mathematicals series contains two routines that must be invoked when using any class.
Failure to initialize a toolkit produces different effects, depending on the library. In some cases, the library may work perfectly; at other times the library can behave erroneously or cause an abnormal program termination.
There are three methods for initializing an Recursion Software toolkit.
Each Mathmetics toolkit uses a reference counting mechanism to track multiple initialization attempts, so it is safe to use all three techniques in the same application. Library initialization is not thread safe, and should only be performed by the primary, or main, thread.
Each toolkit provides a functional interface with the common format
os_init_library_toolkit(); os_exit_library_toolkit();
where library is the name of the component.
The following code fragment shows how the functional interface can be used with Math<ToolKit>.
#include <ospace/math.h>
void
main()
{
// Initialize Math<ToolKit>
os_init_math_toolkit();
// Invoke a Math<ToolKit> method.
...
l_fft.forward(...);
// Cleanup Thread<ToolKit>
os_exit_math_toolkit();
}
Each toolkit contains an initialization object that provides automatic library initialization and cleanup. All initialization objects have the common name
class os_library_toolkit
where library is the name of the component.
The following code fragment shows how the initialization object can be used with Math<ToolKit>.
#include <iostream>
#include <ospace/math.h>
void
main()
{
// Instantiate the Math<ToolKit> initialization object.
os_math_toolkit initialize;
//Use a Math<Toolkit> method
...
l_fft.forward(...);
}
For development on platforms that support dynamic link libraries (DLLs), automatic library initialization can occur through the DLL initialization routine. Although this technique is more convenient than the techniques discussed previously, it uses platform-specific features and can result in non-portable code. Consequently, we recommend using one of the other two initialization techniques discussed.
If your platform supports DLLs, then automatic library initialization is provided by default. Consult the online release notes for more information about your specific platform.
Copyright©1994-2013 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.