uCalc API Version: 5.7.0-preview.1 Released: 7/30/2026
Warning
uCalc API Preview Release Notice:This preview documentation describes the intended behavior of the API. It is not fully accurate or complete.The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.Use of the preview version in your production code is not recommended.
Product:
Class:
Sets the value of a variable by performing a direct memory copy from a given pointer address.
The ValueByPtr method performs a low-level, direct memory copy to set an Item's value. It takes a pointer to a source value and copies the bytes from that memory location into the memory allocated for the target item.
This method is a "power-user" feature intended for performance-critical scenarios or for working with complex data types.
This is a raw memory operation that bypasses uCalc's type-safety checks. The source and destination DataTypes must be compatible and have the same byte size. Using this method with mismatched types can lead to memory corruption, unexpected behavior, or application instability.
vs. Value() Setters: Standard methods like Item.Value(123) or Item.Value("abc") are high-level and type-safe. ValueByPtr is low-level, potentially faster for large or complex data structures by avoiding type conversions, but sacrifices the safety guarantees of the standard methods.
vs. DefineVariable with Memory Binding: When you use uc.DefineVariable("MyVar", &hostVar), you create a persistent link between the uCalc variable and the host variable. Changes are always synchronized. In contrast, ValueByPtr performs a one-time copy at the moment it is called. Subsequent changes to the source value will not affect the destination (see the internal test example below).
ID: 49
using uCalcSoftware;
var uc = new uCalc();
var x = uc.DefineVariable("x = 123");
var y = uc.DefineVariable("y");
y.ValueByPtr(x.ValueAddr());
Console.WriteLine(uc.Eval("x"));
Console.WriteLine(uc.Eval("y"));
123
123 using uCalcSoftware; var uc = new uCalc(); var x = uc.DefineVariable("x = 123"); var y = uc.DefineVariable("y"); y.ValueByPtr(x.ValueAddr()); Console.WriteLine(uc.Eval("x")); Console.WriteLine(uc.Eval("y"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto x = uc.DefineVariable("x = 123");
auto y = uc.DefineVariable("y");
y.ValueByPtr(x.ValueAddr());
cout << uc.Eval("x") << endl;
cout << uc.Eval("y") << endl;
}
123
123 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto x = uc.DefineVariable("x = 123"); auto y = uc.DefineVariable("y"); y.ValueByPtr(x.ValueAddr()); cout << uc.Eval("x") << endl; cout << uc.Eval("y") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim x = uc.DefineVariable("x = 123")
Dim y = uc.DefineVariable("y")
y.ValueByPtr(x.ValueAddr())
Console.WriteLine(uc.Eval("x"))
Console.WriteLine(uc.Eval("y"))
End Sub
End Module
123
123 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim x = uc.DefineVariable("x = 123") Dim y = uc.DefineVariable("y") y.ValueByPtr(x.ValueAddr()) Console.WriteLine(uc.Eval("x")) Console.WriteLine(uc.Eval("y")) End Sub End Module