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 {
<html> | |
<head> | |
<title></title> | |
<style> | |
/* CSS Document */ | |
body { | |
font:12px arial; | |
color: #222; | |
text-align:center; | |
padding:35px; } |
require 'active_record' | |
ActiveRecord::Base.establish_connection({ | |
adapter: 'postgres', # or mysql2 | |
host: 'localhost', | |
username: 'username', | |
password: 'password', | |
database: 'dbname', | |
}) | |
# ActiveRecord::Base.establish_connection("postgres://username:password@host/dbname") |
- Haskell Mergesort | |
- Copyright (C) 2014 by Kendall Stewart | |
First we define a couple of helper functions that | |
will be useful in splitting the list in half: | |
> fsthalf :: [a] -> [a] | |
> fsthalf xs = take (length xs `div` 2) xs |
package main | |
import "fmt" | |
func merge(left []int, right []int) []int { | |
var result []int | |
for len(left) != 0 && len(right) != 0 { | |
if left[0] < right[0] { | |
result = append(result, left[0]) | |
left = left[1:] |
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 {
func yield(count int) chan int { | |
ch := make(chan int) | |
go func() { | |
for i := 0; i < count; i++ { | |
ch <- i | |
} | |
close(ch) | |
}() | |
return ch | |
} |
package main | |
import ( | |
"bytes" | |
"io/ioutil" | |
"github.com/labstack/echo" | |
"github.com/labstack/echo/engine/standard" | |
mw "github.com/labstack/echo/middleware" | |
) |
package main | |
import ( | |
"fmt" | |
"math/rand" | |
) | |
func main() { | |
doneCh := make(chan bool) |
package main | |
import "fmt" | |
func main() { | |
mydict := map[string]int{ | |
"1": 1, | |
"2": 2, | |
"3": 3, | |
} |
package main | |
import ( | |
"fmt" | |
"html/template" | |
"os" | |
"time" | |
) | |
func buildTemplate(name string, leftDelim string, rightDelim string) *template.Template { |