d
Size: a a a
RS
d
var gi int
func var1(sz int) {
s := make([]int, sz)
for i := 0; i < len(s); i++ {
gi += i
s[i] = gi
}
}
s
аллокейтится на heap’е и можно ли это предотвратить?d
In cases where the initial size of a slice is known at compile time, it will begin its allocation on the stack. If this slice’s underlying storage must be expanded based on data only known at runtime, it will be allocated on the heap.
RS
RS
stack
и избавиться от sync.Pool
и для этого было бы неплохо stack аллокейтить в пределах функции валидации дабы избежать лишнего overhead’а. Тот редкий случай когда приходится бороться с компилятором)))C
C
C
C
АП