This is in pool.go
. Originally I was trying to understand how pool.get worked. It brought me down a rabbit hole and I ran into this
func indexLocal(l unsafe.Pointer, i int) *poolLocal {
return &(*[1000000]poolLocal)(l)[i]
}
What is it doing? initializing an array of size 1000000 of poolLocal. and then ... ?
评论:
hlidotbe:
Someone correct me but if I read that correctly it:
- "cast"
l
to a pointer to an array of 1000000 pool local (I guess since it's an unsafe pointer the compiler is OK with that) - returns the address of the pool local item at index
i
The large array size is to avoid tripping whatever boundary check the compiler is inserting I assume. There's no actual array of that size.
lems2:itsmontoya:ty!
You nailed it. One thing to note, this code is changing very soon. If you check tip, they recently improved pool performance.
