为什么切片a
保持不变?是否append()
产生一个新的片?
package main
import (
"fmt"
)
var a = make([]int, 7, 8)
func Test(slice []int) {
slice = append(slice, 100)
fmt.Println(slice)
}
func main() {
for i := 0; i < 7; i++ {
a[i] = i
}
Test(a)
fmt.Println(a)
}
Run Code Online (Sandbox Code Playgroud)
输出:
[0 1 2 3 4 5 6 100]
[0 1 2 3 4 5 6]
Run Code Online (Sandbox Code Playgroud) 我正在实现一个nodejs服务器,它使用mongodb作为数据库和mongodb-native库来连接它.
此外,我正在使用群集来增强服务器性能.因此,有两种方法可以使用mongodb-native驱动程序的连接池;
所以,我的问题是,其中两个中最好的方法是什么?或者还有其他好的方法吗?