How to retrieve the memory pressure information from macOS

Is there a way to retrieve memory pressure information from macOS using Swift or C/C++?

In Activity Monitor, there’s a chart labeled “Memory Pressure” which provides a discrete metric of RAM usage:

Green = system memory usage is fine Yellow = moderate pressure Red = high memory pressure

I’d like to know how to programmatically access this metric.

How to retrieve the memory pressure information from macOS
 
 
Q