<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Memory on Gopher Coding</title><link>https://gophercoding.com/tags/memory/</link><description>Recent content in Memory 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/memory/index.xml" rel="self" type="application/rss+xml"/><item><title>Redis: Connect, Set &amp; Get in Go</title><link>https://gophercoding.com/redis-connection/</link><pubDate>Thu, 04 May 2023 16:00:00 +0000</pubDate><guid>https://gophercoding.com/redis-connection/</guid><description>&lt;p>Redis is a in-memory data store, used a lot in the backend systems of web-apps. Specifically, it&amp;rsquo;s good at helping with caching and message as it&amp;rsquo;s high performance lends itself to fast response times at retriving data.&lt;/p>
&lt;p>In this blog post, we will demonstrate how to connect to Redis using Go and the go-redis library, which is one of the most popular and widely-used libraries for interacting with Redis in Go.&lt;/p></description></item><item><title>Organizing Structs for Memory Efficiency</title><link>https://gophercoding.com/organizing-structs/</link><pubDate>Sun, 30 Apr 2023 06:00:00 +0000</pubDate><guid>https://gophercoding.com/organizing-structs/</guid><description>&lt;p>Go is generally a very memory efficient language to work in, but knowing this little technique can make it that bit &lt;em>more efficient&lt;/em> again.&lt;/p>
&lt;p>First, we&amp;rsquo;ll look at structs - they are a composite data type used to group together zero or more values, each with its own name and type, under a single name. They are the foundation for building complex data structures and objects.&lt;/p>
&lt;!-- raw HTML omitted -->
&lt;!-- raw HTML omitted -->
&lt;p>Memory alignment is an essential aspect to consider when organizing structs in Go. The padding introduced due to alignment can lead to memory waste. To reduce padding and optimize memory usage, follow these guidelines:&lt;/p></description></item><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><item><title>Convert an io.ReadCloser to String</title><link>https://gophercoding.com/convert-readcloser-to-string/</link><pubDate>Sat, 01 Oct 2022 07:00:00 +0000</pubDate><guid>https://gophercoding.com/convert-readcloser-to-string/</guid><description>&lt;p>Using Go, we often make HTTP calls these days using &lt;code>net/http&lt;/code>, which result in a response of type &lt;code>io.ReadCloser&lt;/code>&amp;hellip; which are hard to read for the layman (like me). What we really want to the response in the form of &lt;strong>a string which we can read&lt;/strong>. This post will talk about how to convert these &lt;strong>ReadCloser&lt;/strong> into strings.&lt;/p>
&lt;p>First we&amp;rsquo;ll look at the problem, then we have two different solutions.&lt;/p></description></item></channel></rss>