Best Practices for Transferring Strings From LabVIEW to Shared Libraries

Updated Feb 12, 2024

Reported In

Software

  • LabVIEW

Issue Details

In my application, which is sensitive to performance, I need to transfer a string from LabVIEW to a shared library using a Call Library Node. This Call Library Node function seems to offer several methods for passing strings:
 

1.png

What is the most efficient format for passing a read-only string to my shared library, such as to minimize the number of string copies or memory allocations made?

Solution

"String Handle Pointer" is the only one that does not require some level of extra work on the LV side preparing for the call. For this we simply pass the address of the storage location for the wire. To give an idea of what the others require:
  • C String Pointer:  Adding a null terminator might necessitate reallocating memory. For non-constant parameters, we also need to iterate through the string upon return to determine its length..
  • Pascal String Pointer: It's advisable to avoid this method. It seems we allocate a temporary buffer for copying, but it's best to steer clear altogether.
  • String Handle: Make sure if the handle is null (which is an alternative representation for an empty string) and create a new string handle for empty strings if necessary.