Operations Versus Pointer Dereference

NI-VISA

Operations Versus Pointer Dereference

After the viMapAddress() operation returns the pointer, you can use it to read or write registers. VISA provides the viPeekXX() and viPokeXX() operations to perform the accesses. On many systems, the viMapAddress() operation returns a pointer that you can also dereference directly, rather than calling the LLA operations. The performance gain achievable by using pointer dereferences over operation invocations is extremely system dependent. To determine whether you can use a pointer dereference to perform register accesses on a given mapped session, examine the value of the VI_ATTR_WIN_ACCESS attribute. If the value is VI_DEREF_ADDR, it is safe to perform a pointer dereference.

To make your code portable across different platforms, we recommend that you always use the accessor operations—viPeekXX() and viPokeXX()—as a backup method to perform register I/O. In this way, not only is your source code portable, but your executable can also have binary compatibility across different hardware platforms, even on systems that do not support direct pointer dereferences:

viGetAttribute(instr, VI_ATTR_WIN_ACCESS, &access);
if (access == VI_DEREF_ADDR)

*address = 0x1234;

else

viPoke16(instr, address, 0x1234);