What is sync.Pool in golang and How to use it
sync.Pool (1/2)
Many Go libraries include custom thread-safe free lists, like this:
var objPool = make(chan *Object, 10)
func obj() *Object {
select {
| 5555555555555555 0101010101010101010101010101010101010101010101010101010101010101 size=02 length=00 rotation=00 N=0 immr=000000 imms=111100 | |
| aaaaaaaaaaaaaaaa 1010101010101010101010101010101010101010101010101010101010101010 size=02 length=00 rotation=01 N=0 immr=000001 imms=111100 | |
| 1111111111111111 0001000100010001000100010001000100010001000100010001000100010001 size=04 length=00 rotation=00 N=0 immr=000000 imms=111000 | |
| 8888888888888888 1000100010001000100010001000100010001000100010001000100010001000 size=04 length=00 rotation=01 N=0 immr=000001 imms=111000 | |
| 4444444444444444 0100010001000100010001000100010001000100010001000100010001000100 size=04 length=00 rotation=02 N=0 immr=000010 imms=111000 | |
| 2222222222222222 0010001000100010001000100010001000100010001000100010001000100010 size=04 length=00 rotation=03 N=0 immr=000011 imms=111000 | |
| 3333333333333333 0011001100110011001100110011001100110011001100110011001100110011 size=04 length=01 rotation=00 N=0 immr=000000 imms=111001 | |
| 9999999999999999 100110011001100110011001100 |
| // A simple cgo example for writing to a file. | |
| package main | |
| // #include <stdlib.h> | |
| // #include <stdio.h> | |
| import "C" | |
| import ( | |
| "errors" | |
| "fmt" |
| # alias:northwind | |
| db1.example.com:5432:northwind:postgres:hunter2 | |
| # alias:mainframe | |
| db1.example.com:5432:mainframe:dave:password123 | |
| db1.example.com:5432:unaliased:postgres: |
| import itertools | |
| DIMENSIONS = { | |
| 'city': [ | |
| 'sf', 'nyc', 'la', 'chicago', | |
| ], | |
| 'color': [ | |
| 'red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', | |
| ], |
What is sync.Pool in golang and How to use it
sync.Pool (1/2)
Many Go libraries include custom thread-safe free lists, like this:
var objPool = make(chan *Object, 10)
func obj() *Object {
select {