编写高效的论据 [英] Writing Efficient Arguments

查看:55
本文介绍了编写高效的论据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

指针和引用参数为C ++程序员提供了修改对象的能力。什么更有效,通过指针或引用传递参数

?避免陈腐的刻板冲动

有效的编码风格。相反,请考虑特定场景:

将512MB对象传递给函数。在幕后思考,从

堆栈和堆到程序的物理链接和构建。

Pointer and reference arguments provide C++ programmers with the
ability to modify objects. What is more efficient, passing arguments
via pointer or reference? Avoid the stereotypical urge of debating
effective coding style. Instead, think of particular scenarios:
passing a 512MB object to function. Think behind the scenes, from the
stack and heap to the physical linking and build of the program.

推荐答案

sp*******@gmail.com 写道:
sp*******@gmail.com wrote:

指针和引用参数为C ++程序员提供了修改对象的能力。什么更有效,通过指针或引用传递参数

?避免陈腐的刻板冲动

有效的编码风格。相反,请考虑特定场景:

将512MB对象传递给函数。在幕后思考,从

堆栈和堆到程序的物理链接和构建。
Pointer and reference arguments provide C++ programmers with the
ability to modify objects. What is more efficient, passing arguments
via pointer or reference? Avoid the stereotypical urge of debating
effective coding style. Instead, think of particular scenarios:
passing a 512MB object to function. Think behind the scenes, from the
stack and heap to the physical linking and build of the program.



无从告诉。这是所有特定于平台的。如果实现在幕后使用

指针,则可能没有什么区别。


如果它很重要,请说明。如果没有,那么使用大多数

的构造清楚地表示程序的意图。


Brian


No way to tell. It''s all platform-specific. If the implementation uses
pointers behind the scenes, there''s likely little difference.

If it''s important, profile. If not, then use the construct that most
clearly represents the intent of the program.

Brian


sp*******@gmail.com 写道:

指针和引用参数为C ++程序员提供了修改对象的能力。什么更有效,通过指针或引用传递参数

?避免陈腐的刻板冲动

有效的编码风格。相反,请考虑特定场景:

将512MB对象传递给函数。在幕后思考,从

堆栈和堆到程序的物理链接和构建。
Pointer and reference arguments provide C++ programmers with the
ability to modify objects. What is more efficient, passing arguments
via pointer or reference? Avoid the stereotypical urge of debating
effective coding style. Instead, think of particular scenarios:
passing a 512MB object to function. Think behind the scenes, from the
stack and heap to the physical linking and build of the program.



我建议我们禁止单词高效来自新闻组的帖子除非

这张海报已经过基准测试,并证明他实际上想要的微优化可能会有所作为。

I propose that we ban the word "efficient" from newsgroup posts unless
the poster has benchmarked and shown that the micro-optimization he
wants actually may do something.


7月9日下午7:03,spekyu ... @ gmail.com写道:
On Jul 9, 7:03 pm, spekyu...@gmail.com wrote:

指针和引用参数为C ++程序员提供了

修改对象的能力。什么更有效,通过指针或引用传递参数

?避免陈腐的刻板冲动

有效的编码风格。相反,请考虑特定场景:

将512MB对象传递给函数。在幕后思考,从

堆栈和堆到程序的物理链接和构建。
Pointer and reference arguments provide C++ programmers with the
ability to modify objects. What is more efficient, passing arguments
via pointer or reference? Avoid the stereotypical urge of debating
effective coding style. Instead, think of particular scenarios:
passing a 512MB object to function. Think behind the scenes, from the
stack and heap to the physical linking and build of the program.


>从内存的角度来看,没有区别。假设
>From memory standpoint there is no difference. Assuming the address of



的地址,引用和指针来自同一位置,我不认为
相信还有其他说明设置堆栈;

然而,一旦我这样说,有人会引用一些实现

它的确如此。


''效率''在收件人中。也就是说,它不必检查
检查引用是否为null - 因为引用永远不能为null。

最后,我怀疑你是否将指针参数声明为''void *'',你

失去类型检查效率,或招致类型检查效率低下

,具体取决于你的观点。

the reference and pointer are coming from the same location, I don''t
believe there are additional instructions to set up the stack;
however, as soon as I say that, someone will cite some implementation
where it does.

The ''efficiency'' is in the recipient. That is, it does not have to
check if a reference is null - since a reference can never be null.
Finally, I suspect if you declare a pointer parameter as ''void*'', you
lose type-checking efficiency, or incur type-checking inefficiency
depending on your point-of-view.


这篇关于编写高效的论据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆