Golang 错误函数参数对于新的 goroutine 来说太大了

Golang error function arguments too large for new goroutine

我是 运行 一个带有 go 1.4 的程序,我正在尝试将一个大结构传递给一个 go 函数。

go ProcessImpression(network, &logImpression, campaign, actualSpent, partnerAccount, deviceId, otherParams)

我收到这个错误:

runtime.newproc: function arguments too large for new goroutine

我已经改为通过引用传递,这很有帮助,但我想知道是否有某种方法可以在 go 函数中传递大型结构。

谢谢,

没有,none我知道。

我不认为你应该过于积极地调整以避免复制,但它出现 from the source that this error is emitted when parameters exceed the usable stack space for a new goroutine, which should be kilobytes. The copying overhead is real at that point, especially if this isn't the only time these things are copied. Perhaps some struct either explicitly is larger than expected thanks to a large struct member (1kb array rather than a slice, say) or indirectly. If not, just using a pointer as you have makes sense, and if you're worried about creating garbage, recycle the structs pointed to using sync.Pool

在处理大结构的值列表 ([]BigType) 时遇到此问题:

for _, stct := range listBigStcts {
    go func(stct BigType) {
        ...process stct ...
    }(stct) // <-- error occurs here

}

解决方法是将 []BigType 替换为 []*BigType

我能够通过更改

中的参数来解决此问题
func doStuff(prev, next User)

func doStuff(prev, next *User)

@twotwotwo 在 中的回答非常有帮助。