Search code examples
c++vectorlabview

Native Vector<Double> in LabView as an Argument/Return


I am making a wrapper for C++ DLLs. In the function I need to return a vector<double>. I studied the documents and read that we can only return int and string. For returning any other variables we need to pass it as an argument. But the available variable types are Numeric, String, Array. So how can I get vector<double> from the native function in LabView.


Solution

  • In C++ vector is stored as an array, if v is vector <double> first element address is &v[0]. In LabVIEW CLFN node allows you to pass an array by pointer or by handle. So, you have 3 solutions:

    1. Pass a pre-allocated array into your DLL (by pointer), fill it in, it will be available after the CLFN finishes execution.
    2. Pass an array to the CLFN by handle, resize it accordingly by LabVIEW memory manager, and the contents of the array will be available after the CLFN finishes execution.
    3. If the array is really big (100s of MB), and you really have to use std:vector in your C++ code I would suggest to define your own allocator based on LabVIEW memory manager to avoid copying.