uCalc API Version: 2.1.3-preview.2 Released: 6/16/2026

Warning

uCalc API Preview Release Notice:The documentation describes the intended behavior of the API. The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.

ValuePtr()

Method

Product: 

Fast Math Parser

Class: 

Item

Retrieves the pointer value stored within a pointer-type variable.

Syntax

ValuePtr()

Parameters

[None]

Return

IntPtr

The memory address stored in the variable as a pointer.

Remarks

The ValuePtr() method retrieves the value of an Item that is defined as a pointer type. This allows you to work with memory addresses within the uCalc engine, enabling powerful interoperability with native code.

ValuePtr() vs. ValueAddr()

Understanding the difference between ValuePtr() and ValueAddr() is crucial for correct pointer manipulation. They answer two different questions:

  • ValueAddr(): "What is the memory address of this variable?" (like &myVar in C++).
  • ValuePtr(): "What is the memory address stored inside this variable?" (like myPtrVar in C++, where myPtrVar holds an address).
MethodAnalogy (C++)DescriptionUse Case
item.ValueAddr()&variableReturns the memory address where the item's own value is stored.Getting a pointer to a variable to pass to another function.
item.ValuePtr()pointer_variableReturns the value contained within the item, assuming that value is a pointer.Dereferencing a pointer variable that you have already stored.

This is best illustrated by the AddressOf function. When you define a pointer variable like xPtr As Ptr = AddressOf(x), the ValuePtr() of xPtr will be equal to the ValueAddr() of x.

Why uCalc? (Comparative Analysis)

  • vs. C++ void* / reinterpret_cast: In C++, working with generic pointers often involves unsafe casting and manual memory management. uCalc provides a managed environment where pointer variables are still strongly typed (e.g., Int Ptr, String Ptr), reducing the risk of type-related memory errors.

  • vs. C# IntPtr and unsafe code: To achieve similar functionality in C#, you would typically need to enter an unsafe code block and work with raw pointers. uCalc abstracts this away, providing a safe, cross-language mechanism to pass memory references between the scripting engine and the host application without requiring unsafe contexts in your C# code.

This makes ValuePtr() a key feature for building high-performance bridges between uCalc expressions and native libraries.

Examples

Using ValuePtr
				
					using uCalcSoftware;

var uc = new uCalc();
var xVar = uc.DefineVariable("x = 123");
var xVarPtr = uc.DefineVariable("xPtr As Double Ptr = AddressOf(x)");

Console.WriteLine((xVarPtr.ValuePtr() == xVar.ValueAddr()));
				
			
True
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

#define tf(IsTrue) ((IsTrue) ? "True" : "False")

int main() {
   uCalc uc;
   auto xVar = uc.DefineVariable("x = 123");
   auto xVarPtr = uc.DefineVariable("xPtr As Double Ptr = AddressOf(x)");

   cout << tf((xVarPtr.ValuePtr() == xVar.ValueAddr())) << endl;
}
				
			
True
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim xVar = uc.DefineVariable("x = 123")
      Dim xVarPtr = uc.DefineVariable("xPtr As Double Ptr = AddressOf(x)")
      
      Console.WriteLine((xVarPtr.ValuePtr() = xVar.ValueAddr()))
   End Sub
End Module
				
			
True