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.
DiagMem
Method
Product:
Class:
Provides a programmatic way to query uCalc's internal memory usage, detailing allocations for specific internal object types or the entire engine.
Syntax
Parameters
Return
int
Returns the requested memory metric (e.g., total bytes, number of active elements) based on the Count and Option parameters.
Remarks
The DiagMem method offers advanced diagnostic capabilities for monitoring uCalc's internal memory footprint. While primarily intended for internal testing and development, it is invaluable for developers seeking to optimize performance, troubleshoot memory-related issues, or understand the resource consumption of complex expressions within their applications.
Parameters Explained
uCalcIndex: This parameter identifies the specific uCalc engine instance whose memory you wish to diagnose. The index can be obtained by calling the uCalc.MemoryIndex method on any object associated with that engine instance.Target: Use a member of the uCalc.BuiltInType enumeration to specify which internal component's memory you want to inspect. Use aDiag*member, such asBuiltInType::DiagParsedExpressionfor parsed expression trees,BuiltInType::DiagDataTypefor internal data type definitions, orBuiltInType::DiagAllto get a consolidated view.Count: This parameter, utilizing the DiagMemCount enumeration, determines what metricDiagMemshould return. You can choose to count the totalBytesconsumed, the number of activeElements, or other metrics.Option: This parameter, using the DiagMemOption enumeration, refines the memory measurement. Options includeDefault(typicallyActive),Active(current memory usage), orPeak(maximum memory usage observed since the uCalc instance's creation).
Comparative Analysis: Why uCalc's DiagMem?
Traditional memory profiling often involves external tools like Valgrind (for C/C++), Visual Studio Diagnostic Tools, or language-specific profilers. While powerful for application-wide analysis, they may not provide granular insight into the specific internal data structures of a component like uCalc.
DiagMem offers a unique advantage: it is an integrated, programmatic memory profiler specifically tailored for the uCalc engine. Instead of interpreting complex external profiler reports, developers can directly query uCalc's internal state. This allows for:
- Fine-grained Component-Level Analysis: Pinpoint memory usage for specific uCalc elements like parsed expressions, data tables, or internal type definitions.
- Runtime Monitoring: Integrate memory checks directly into application logic for real-time diagnostics or dynamic resource management.
- Automated Testing: Incorporate memory assertions into unit or integration tests to prevent regressions in memory efficiency.
- Simplified Troubleshooting: Quickly identify if a particular type of expression or function definition is consuming excessive memory without needing to attach an external profiler.