Performs a direct memory read of a variable's value, reinterpreting the first 16 bits as a signed integer.
Product:
Class:
Warning
uCalc API Preview Release Notice:The uCalc engine has successfully transitioned to modern cross-platform environments.The next phase envolves some structural changes, performance optimizations, and API refinements.The API is subject to breaking changes prior to the stable release. Please evaluate the preview version thoroughly before production use.
Returns a 16-bit integer
The ValueInt16() method is a low-level, high-performance accessor that reads the value of a uCalc Item by interpreting its first 16 bits (2 bytes) of memory as a signed integer (short in C#).
This method does not perform type checking or conversion. It is a direct memory operation.
Int16, it correctly returns the variable's value.Int32: It will read the lower 16 bits of the 32-bit integer.Double: It will read the first 2 bytes of the 8-byte floating-point representation, resulting in a value that is not numerically related to the original double.String: It will read the first 2 bytes of the internal string object's memory (which could be part of a pointer or length field), leading to unpredictable results.For safe, type-converting access, use ValueStr() and parse the resulting string.
This method's behavior is analogous to low-level type punning operations in other languages, designed for performance at the cost of safety.
reinterpret_cast: Functionally similar to casting a pointer of one type to a short* and dereferencing it. It's a powerful tool for performance-critical code but bypasses the type system.BitConverter.ToInt16: Similar to taking the first two bytes from another type's byte array and converting them to a short.Use this method only when performance is critical and the data type is guaranteed.
This page last modified on: