PSJ. - JSON Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > JSON - Parser > Parser-Operations > !Node Operations >

PSJ. - JSON Operations

PSJ.GetNodeCount

Previous Top Next


SPR Script Language

 

PSJ.GetNodeCount

Gets the current total number of nodes allocated by the JSON library.

 

Intention

 

The PSJ.GetNodeCount command is a diagnostic tool used to retrieve the current high-water mark of allocated nodes in the JSON library. This number represents the highest index used in the internal node arrays and is a useful indicator of memory consumption and data structure complexity.

 

It is particularly valuable for monitoring the effect of operations like parsing large documents, deleting nodes with PSJ.FreeTree, and running memory optimization with PSJ.Compact.

 

Syntax

 

PSJ.GetNodeCount[|$$RET]

 

Parameter Explanation

 

P1 - $$RET - (Variable, Numeric, Optional)

The variable to store the numeric node count. If omitted, the count is returned on the top-of-stack (TOS).

 

Examples

 

'***********************************

' PSJ.GetNodeCount - Sample 1: Monitoring node allocation

'***********************************

PSJ.Reset

VAR.$$JSN={"a":1,"b":[2,3]}

 

' Get count after reset (should be 0)

PSJ.GetNodeCount|$$CNT

MBX.Initial node count:|$$CNT

 

' Parse a small JSON document

PSJ.Parse|$$JSN|$$H_1

 

' Get count after parsing

PSJ.GetNodeCount|$$CNT

MBX.Node count after parsing:|$$CNT

 

PSJ.Free|$$H_1

END.

 

 

Remarks

 

- The node count is a high-water mark. It increases as nodes are created but does not decrease when nodes are freed with PSJ.FreeTree or PSJ.Free. This creates empty slots, or fragmentation.

- To reset the node count and eliminate fragmentation, use the PSJ.Compact command.

 

See also:

 

PSJ.Compact

PSJ.FreeTree

PSJ.Reset