Pointer Variable

A pointer can point to a variable, an array of variables, a structure, an array of structures, or a user-defined function.

Syntax

Dim ptr as long

Ptr = @MyVariable

OR

MyVariable = !ptr

Remarks

A pointer can point to a variable, an array of variables, a structure, an array of structures, or a user-defined function. Pointers are a convenient way to reference the memory location of a variable in a program rather than referencing it by name. Pointers are useful in functions where parameters are local to the function and changes to the parameters have no effect on the original arguments.

Pointer variables must be initialized by the @ operator before they can be used. E.g.,

PTR as Long!
PTR = @X

Reference to an uninitialized pointer will return a variable out of bounds error.

In most applications, pointer variables are declared as Type Long! However, pointer variables may also be declared as type Float!, Boolean!, or String! (for example, Dim P as Float!).

@ - The "@" symbol is used to reference the memory location of a variable in a program

! – The "!" symbol is used to dereference a pointer. This will return the value at the pointer rather than the memory location of the pointer.

! (VariableName) – The "()" around the variable name will return the variable name associated with the memory location. This must be declared as type string.

Pointers can also be used with Functions (see Example Program).

!Pointer(X)

This will access the xth element of an array of pointers.

The ! operator can also be applied to a user function call, when the function returns a pointer. For example:

Function ConstrainFunc(Value As Long,Low As Long,High As Long) As Long
  If !Value < !Low Then
    Return Low
  ElseIf !Value > !High Then
    Return High
  Else
    Return Value
  EndIf
EndFunction
'Call within program
FuncFltRes = !ConstrainFunc(@FltVal,@FltLow,@FltHigh)

A pointer referenced inside an expression can also be cast as a specific type (e.g., !(FLOAT!)(p+1) = !(FLOAT!)(p-3) + !(float!)(p-2) ).

Due to how memory is managed in the datalogger, there cannot be more than 4094 variable declarations before declaring a variable that will be accessed via a pointer. Additionally, the size of an array that can be accessed via a pointer is limited to 1,048,576.

Pointers can reference values in data tables by using the TableName.Fieldname syntax. This allows both writing and reading via a pointer reference to a data table.