Grokking Concurrency in Go
Vote

0% completed

​

Pool: Reusing Objects

Some programs keep a set of temporary objects that goroutines take, use for one short task, and give back. The next goroutine can then use a returned object instead of allocating a new one. Such a set is called a pool. Go provides it as sync.Pool, and its documentation describes its purpose as caching allocated but unused items for later reuse, so that the garbage collector has less work to do.

The objects in a pool are usually buffers. A server that formats a response, encodes a JSON body, or builds a log line needs a few kilobytes of scratch memory for each request and nothing afterward

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content