uCalc API Version: 2.1.3-preview.2 Released: 6/17/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.
ValueByPtr
Method
Product:
Class:
Sets the value of a variable by performing a direct memory copy from a given pointer address.
Syntax
Parameters
Return
void
Remarks
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.
⚠️ Crucial Safety Note
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.
Comparative Analysis
vs.
Value()Setters: Standard methods likeItem.Value(123)orItem.Value("abc")are high-level and type-safe.ValueByPtris low-level, potentially faster for large or complex data structures by avoiding type conversions, but sacrifices the safety guarantees of the standard methods.vs.
DefineVariablewith Memory Binding: When you useuc.DefineVariable("MyVar", &hostVar), you create a persistent link between the uCalc variable and the host variable. Changes are always synchronized. In contrast,ValueByPtrperforms 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).
Examples
Setting a variable value by pointer
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