企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
* 如果是map结构体用后就删除 * 结构体切片, 循环取出和放入 ~~~ package main import ( "fmt" "sync" ) type ResConnectorInfos struct { StationId string //充电站Id EquipmentId string //充电桩Id ConnectorId string //充电枪Id } func main() { ppFree := sync.Pool{New: func() interface{} { return new(ResConnectorInfos) }} res := ppFree.Get().(*ResConnectorInfos) res.StationId = "1" fmt.Printf("%p%v\n", res, res) res.StationId = "" res.ConnectorId = "" res.EquipmentId = "" ppFree.Put(res) res3 := ppFree.Get().(*ResConnectorInfos) fmt.Printf("%p%v\n", res3, res3) } ~~~