> For the complete documentation index, see [llms.txt](https://lukasz-nowakiewicz.gitbook.io/resources/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lukasz-nowakiewicz.gitbook.io/resources/golang/useful-snippets.md).

# Useful Snippets

This page provides useful snippets that could be used in the codebase.

## Memory allocation

````
```go
package main

import (
	"fmt"
	"runtime"
)

func printAlloc() {
	var m runtime.MemStats
	runtime.ReadMemStats(&m)
	fmt.Printf("%d MB\n", m.Alloc/1024/1024)
}

func main() {
	printAlloc()
}
```
````
