auto&prefetch

来源:互联网 发布:算法精解 pdf 百度云 编辑:程序博客网 时间:2024/06/05 04:28

auto项目开始对auto解禁了之后,才开始使用,起码对于vector<xxx>::iterator这样的代码起了很大的简洁的作用。

后来发现在写多个版本的代码的时候也让一切变得很简洁,比如原来是:

#if BONESETBoneSet* bone = GetBoneRoot();#elseBoneNode* bone = GetBoneRoot();#endif

使用auto的时候就可以是

auto bone = GetBoneRoot();

但是其中也容易犯错误,尤其是程序员自大的以为可以不看文档就直接使用(比如当时的我),如果返回的是const type&的话使用auto的时候,需要也带上引用符号和const这样的修饰符,auto演绎出来的只是类型。

msdn上面的文档:

The auto keyword deduces the type of a declared variable from its initialization expression.

To use the auto keyword, declare a variable with the auto keyword instead of a type, and specify an initialization expression. In addition, you can modify the auto keyword with specifiers and declarators such as const, volatile, pointer (*), reference (&), and rvalue reference (&&). The compiler evaluates the initialization expression and then uses that information to deduce the type of the variable.

 

prefetch

就是提前把一部分内存加载到cache里面,防止在用的时候产生cache miss,消耗大量的性能,以前在console上开发的时候常常使用这个,对优化很有好处,在pc上面以为是没有的,但是后来发现sse库里面有这个支持,非常棒:

http://msdn.microsoft.com/en-us/library/cyxt4d09(v=vs.71).aspx


 

原创粉丝点击