[英]Scope resolution and the this operator
In a (C++) class I took recently the teacher mentioned that using the ->
operator was a tiny bit slower than using dot notation and dereferencing your pointer manually (eg (*ptr)
). 在我最近采用的(C ++)课程中,老师提到使用
->
运算符比使用点表示法和手动取消引用指针(例如(*ptr)
)要慢一点。
The ->
operator is neither slower or faster than .
->
运算符既不慢也不快.
operator. 运营商。 The fact is that dereferencing something is slower than just access to a memory location, because there is one more indirection.
事实上, 取消引用某些东西比访问内存位置要慢,因为还有一个间接。 And this is a fact of life, either in C and C++ and any other language.
这是生活中的事实,无论是在C和C ++以及任何其他语言中。
In C++, you have also references , so you can dereference something using the .
在C ++中,您还有引用 ,因此您可以使用引用来取消引用
.
too! 太! So the problem here is not arrow-vs-dot , the problem is if the compiler can go straight to a value or if it must search for its address before.
所以这里的问题不是arrow-vs-dot ,问题是如果编译器可以直接找到一个值,或者它是否必须先搜索它的地址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.