使用POD高效地上课 [英] Efficiently moving a class with PODs

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

问题描述

如何有效地移动具有大量POD成员的课程?示例:

How do I efficiently move a class with a large set of POD members? Example:

struct{
    int a1;
    int a2;
    int a3;
    ...
    ...
    ...
};

移动是指行为类似于移动语义(std :: move) 。

By 'move' I mean that the behavior is similar to the move semantic (std::move).

推荐答案

POD不会移动,它们只是复制而已。因为没有间接关系。因此,只需使用普通分配,然后要求编译器针对您考虑的效率进行优化。记住要有条不紊地进行测量(在地球上您正在做的事情有所不同)之前和之后。还应考虑浪费的程序员时间(金钱)是否值得进行微优化。

PODs don't move, they just copy. Because there's no indirection. So just use an ordinary assignment, and ask the compiler to optimize for whatever efficiency you have in mind. Remember to measure, systematically, before (what on Earth you are doing differently) and after. Also consider whether the wasted programmer time, which is money, is worth the micro-optimization.

这篇关于使用POD高效地上课的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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