Memory · Gopher Coding (original) (raw)

Tag: Memory

Redis: Connect, Set & Get in GoRedis is a in-memory data store, used a lot in the backend systems of web-apps. Specifically, it’s good at helping with caching and message as it’s high performance lends itself to fast response times at retriving data. 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.

#redis#connection#get#set#goredis#memory#store#package

Organizing Structs for Memory EfficiencyGo is generally a very memory efficient language to work in, but knowing this little technique can make it that bit more efficient again. First, we’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. 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:

#memory#alignment#padding#cpu#hardware#struct#optimization#bytes

Print Current Memory UsageIn this post we show how you can print memory usage in golang. We do this by outputting the current state of memory at any given time to show how much ram has been allocated and gc cycles made. We have created a function PrintMemUsage() to help out, so you can call this when ever you need to know. All the info we need can be acquired through the runtime [docs] package, which allows us to read the state of the memory into the MemStats 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 garbage collections.

#memory#stats#runtime#package#stdlib#memstats#alloc#garbage#gc#os

Convert an io.ReadCloser to StringConvert an io.ReadCloser to StringUsing Go, we often make HTTP calls these days using net/http, which result in a response of type io.ReadCloser… which are hard to read for the layman (like me). What we really want to the response in the form of a string which we can read. This post will talk about how to convert these ReadCloser into strings. First we’ll look at the problem, then we have two different solutions.

#readcloser#io#convert#string#conversion#ioutil#buffer#memory#http#net