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 {
<?php | |
//get valid random socket port with php | |
$s = stream_socket_server("tcp://localhost:0"); | |
$ss = stream_socket_get_name($s,0); | |
$pos = | |
strrpos($ss,":"); |
<?php | |
//HTTP server xample: hello world with php | |
//php myhttp.php | |
//open http://localhost:7788/ | |
$h = stream_socket_server("tcp://0.0.0.0:7788"); | |
print_r($h); | |
<?php | |
//stack is for LookBack (2018-10-22) | |
$d=range(1,10); | |
function p($d) {return print_r($d);} | |
<?php | |
use Parle\{Lexer,Parser,Token,Stack}; | |
$p = new Parser(); | |
/*** | |
a=1; | |
b=2; |
<?php | |
// based on https://github.com/axgle/Naive-Bayes-Classifier | |
class NativeBayes{ | |
static function classify($table,$features,$category){ | |
$db=new pdo("mysql:dbname=bayes","root","root"); | |
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_ASSOC); | |
$sql="select distinct($category) from $table"; | |
$arg=array(); | |
foreach($db->query($sql)->fetchAll() as $row){ |
<?php | |
function year_by_month($start=null,$end=null) { | |
$data=array(); | |
$start=strtotime($start); | |
if($end===null){ | |
$end=date("Y-m-d"); | |
} | |
$end=strtotime($end); | |
$m_start=date("Y",$start)*12+(int)date("m",$start); | |
$m_end=date("Y",$end)*12+(int)date("m",$end); |
package main | |
import ( | |
"github.com/nsf/termbox-go" | |
) | |
var row int = 0 | |
func echo(str string) { | |
x := 0 |
<?php | |
// http://www.php.net/shuffle | |
//http://www.cnblogs.com/Jerry-Chou/archive/2012/01/04/2311610.html | |
function sh($arr){ | |
$n=count($arr); | |
while($n>1){ | |
$n--; | |
$k=rand(0,$n); | |
$tmp=$arr[$n]; | |
$arr[$n]=$arr[$k]; |
<?php | |
class db{ | |
static $count=0;//current data | |
static $undos=array();//stack | |
} | |
function add($n){ | |
db::$count+=$n; | |
db::$undos[]=function() use($n){ | |
db::$count-=$n; |
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 {