<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Stdlib on Gopher Coding</title><link>https://gophercoding.com/tags/stdlib/</link><description>Recent content in Stdlib on Gopher Coding</description><generator>Hugo</generator><language>en-gb</language><lastBuildDate>Mon, 25 Dec 2023 22:19:25 +0000</lastBuildDate><atom:link href="https://gophercoding.com/tags/stdlib/index.xml" rel="self" type="application/rss+xml"/><item><title>Print Current Memory Usage</title><link>https://gophercoding.com/print-current-memory-usage/</link><pubDate>Mon, 05 Dec 2022 17:00:00 +0000</pubDate><guid>https://gophercoding.com/print-current-memory-usage/</guid><description>&lt;p>In this post we show how you can print memory usage in golang. We do this by outputting the current &lt;strong>state&lt;/strong> of memory at any given time to show how much ram has been allocated and gc cycles made. We have created a function &lt;code>PrintMemUsage()&lt;/code> to help out, so you can call this when ever you need to know.&lt;/p>
&lt;p>All the info we need can be acquired through the &lt;code>runtime&lt;/code> [&lt;a href="https://pkg.go.dev/runtime">docs&lt;/a>] package, which allows us to read the state of the memory into the &lt;code>MemStats&lt;/code> struct. It returns stats like how much memory the program is using, how much of it the OS has allocated to it and the number of &lt;em>garbage collections&lt;/em>.&lt;/p></description></item></channel></rss>