Article
· Jul 13, 2023 2m read

How to get the size of a global programmatically

InterSystems FAQ rubric

It can be obtained by using the Size query of the system-provided %SYS.GlobalQuery class.

See the sample code below for usage examples.
*Please check the class reference for specifying columns and parameters.

 set dir="C:\intersystems\iris\mgr\user" // IRIS.DAT(or CACHE.DAT) folder
 set rs = ##class(%ResultSet).%New("%SYS.GlobalQuery:Size")
 do rs.Execute(dir) // You can also specify a mask with the 3d parameter
 while (rs.Next()) { 
   set gname= rs.Get("Name") // global name
   set gsize= rs.Get("Used MB") // global size (MB)
   write gname," : ",gsize,!
 }

If the size of the global variable is large, it may take a long time to retrieve it. In that case, when executing the Size query, specify 1 for the 6th argument and re-execute the query.

By specifying the sixth argument, get the size in simple mode. "Used MB" cannot be obtained because of simple mode, but "Allocated MB" can be obtained.

Below is an example of execution when the 6th argument is specified (Allocated MB is obtained instead of Used MB).

 set dir="C:\intersystems\iris\mgr\user" // IRIS.DAT(or CACHE.DAT) folder
 set rs = ##class(%ResultSet).%New("%SYS.GlobalQuery:Size")
 do rs.Execute(dir,,,,,1) // You can also specify a mask with the 3d parameter
 while (rs.Next()) { 
   set gname= rs.Get("Name") // global name
   set gsize= rs.Get("Allocated MB") // global size (MB)
   write gname," : ",gsize,! 
 }
Discussion (0)0
Log in or sign up to continue