06-11-2009 05:25 AM
I know that Labview essentialy crashes when one tries to allocate array in C without using
Labview memory manager.The mystery for me now is, how I successed till now to initialize usual variables in C,
objects in C++ using "new" , etc. Probably this is a question to NI.
thanks
06-11-2009 08:22 AM
mishklyar wrote:I know that Labview essentialy crashes when one tries to allocate array in C without using
Labview memory manager.The mystery for me now is, how I successed till now to initialize usual variables in C,
objects in C++ using "new" , etc. Probably this is a question to NI.
thanks
As long as you do not pass them in a variable LabVIEW does interpret to be its own datatype there is no problem.
Basicilly in C++ you have very specific datatypes that are only meaningfull in terms of memory management for the same type of C++ runtime and version that was instantiated by the current C++ process. In the case of Visual C++ applications that are compiled with the dynamic runtime option and an appication using the same option Microsoft makes usually sure that there is no problem with that.
In LabVIEW the thing is similar in that resizabel datatypes such as strings and arrays need to be allocated, manipulated and deallocated by the same LabVIEW runtime memory manager.
As long as you use standard C datatypes other rules apply. The buffers are always allocated by the caller no matter what and a callee has no possibility to resize such buffers on its own. So for output buffers they are either allocated to big or just with the right size by the caller and everything works right or they are to small (including not allocated) and the DLL will crash (immediately or later on) if it tries to fill in that buffer.
There is no problem in allocating C++ variables in a DLL as long as you pass them back to LabVIEW as an opaque pointer (int32 vlaue) that LabVIEW does not try to interpret, access or reference in any way, to let LabVIEW pass it back to other DLL functions that know what to expect in the pointer.
If you however create a C++ string object and pass it back as a pointer and tell LabVIEW that this is a C string pointer you are in deep sh*t.
Rolf Kalbermatter