在链接器脚本中,我定义了PROVIDE(__KERNEL_BEGIN__ = .);.
地址可以从以下地址访问:
extern uint32_t __KERNEL_BEGIN__[];
Run Code Online (Sandbox Code Playgroud)
但是,以下不起作用(给出错误的地址):
extern uint32_t * __KERNEL_BEGIN__;
Run Code Online (Sandbox Code Playgroud)
我看着集会.第一种方法__KERNEL_BEGIN__提供了确切的地址.第二个,__KERNEL_BEGIN__ = [address]在地址处查找值.
那么,一定是这样吗?我无法区分.
我读了sync.Pool设计,但发现有两种逻辑,为什么我们需要localPool来解决锁竞争。我们可以使用chan来实现一个。
使用频道的速度是的4倍sync.pool!
除了池可以清除对象外,它还有什么优势?
这是池实现和基准测试代码:
package client
import (
"runtime"
"sync"
"testing"
)
type MPool chan interface{}
type A struct {
s string
b int
overflow *[2]*[]*string
}
var p = sync.Pool{
New: func() interface{} { return new(A) },
}
var mp MPool = make(chan interface{}, 100)
func get() interface{} {
select {
case r := <-mp:
return r
default:
return new(A)
}
}
func put(a interface{}) {
select {
case mp <- a:
default:
}
return …Run Code Online (Sandbox Code Playgroud)