LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Memory allocation of in/out pointer from dll

Solved!
Go to solution

The question I have is fairly generic so I will keep my example the same way.

 

Lets say I have a dll with the following function (exclude all the dll export stuff):

  • void myFunction(int* value);

 

For the sake of this discussion lets assume that the import shared library wizard works properly and the function vi works as expected.

 

I mainly live in the C/C++ world so I know that I would need to created the memory this this item before calling the function.  Such as:

  • int* value = new int();
  • my function(value);

Or

just passing by reference:

  • int value;
  • myFunction(&value);

 

Being new to LabView it is not obviously clear as to how this memory gets allocated.

 

Since this is an "in/out" I have three options:

  1. Only pass a value IN:  Such as a numeric constant which I can make the assumption that this allocates memory for me.
  2. Pass something IN and OUT: Same as #1 I can assume memory is allocated because I passed in a value.
  3. Only consume what comes out.  This is the case I am interested in.  Does LabView allocate this memory or do I need to do it?

 

With all that said the function seems to work.  Even with multiple instances I have not seen any issues; however, it seems a bit weird to me.

 

In summary, does LabView allocate the memory of an In/Out pointer when passing through a shared library node? Is it true for all primitive data types? Including structures of primitive data types? Specifically ones with defined size (i.e. not dynamic arrays int[])

0 Kudos
Message 1 of 2
(2,420 Views)
Solution
Accepted by topic author Mitch9192

@Mitch9192 wrote:

Only consume what comes out.  This is the case I am interested in.  Does LabView allocate this memory or do I need to do it?

 

In summary, does LabView allocate the memory of an In/Out pointer when passing through a shared library node? Is it true for all primitive data types? Including structures of primitive data types? Specifically ones with defined size (i.e. not dynamic arrays int[])


For any fixed-size type (a basic type such as an integer, or a cluster of them) LabVIEW will allocate the memory for you because it knows how large the data is. For an array or a string, you need either to allocate the memory yourself (for example, with Initialize Array) or set the minimum array size in the Call Library Function Node configuration.

Message 2 of 2
(2,416 Views)