Go语言中有移动语义吗?

huangapple go评论89阅读模式
英文:

Is there move semantics in Go

问题

我猜测从函数返回的对象(类似于New()风格的构造函数)会被隐式地移动到外部。

在Go语言中,已经存在指针和隐式引用语义(如切片、映射、通道和闭包捕获),除了copy之外,移动语义是另一种在特定内存上操作的方式,这在C++和Rust中用于内存效率。

英文:

I guess an object returned from a function (like New() style constructors) is moved outside, which is done by compiler implicitly.

There are already pointers and implicit reference semantics (slice, map, chan, and closure capture) in Go, except copy, and move semantics is another way to operate on some specific memory, which exists in C++ and Rust for memory efficiency.

答案1

得分: 2

Go语言中没有移动语义。

英文:

> Is there move semantic in Go [?]

No.

答案2

得分: 0

根据Go官方文档,没有明确的移动操作语法。如果有的话,那将由编译器实现定义,而不是语言规范。

英文:

According to Go official document, there is no explicit syntax for move operation. If there is any, that would be defined by the compiler implementation, not language specification.

huangapple
  • 本文由 发表于 2021年9月29日 16:08:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/69372675.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定