March 2020
Intermediate to advanced
406 pages
8h 39m
English
The ReadMemStats() function reads memory allocator statistics and populates them into a variable, say, m. The MemStats struct has a lot of really valuable information about in-flight memory utilization. Let's take a deep look into what values it can produce for us. An HTTP handler function that allows us to see the memory utilization of the binary may be helpful as we make more requests in our system and wish to see where our memory allocation is utilized:
package main import ( "fmt" "net/http" "runtime") func memStats(w http.ResponseWriter, r *http.Request) { var memStats runtime.MemStats runtime.ReadMemStats(&memStats)
Read now
Unlock full access