将原子int的向量强制转换或转换为int的向量的有效方式 [英] efficent way of casting or converting vector of atomic int to vector of int

查看:55
本文介绍了将原子int的向量强制转换或转换为int的向量的有效方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实有一个整数向量,我想确保增量操作在线程安全的情况下发生,因此在所有并行增量之后我使用了 std :: vector< std :: atomic< int> 我需要非原子向量 std :: vector< int> .有没有一种有效的方法可以不进行复制?向量很大,性能非常重要.

I do have a vector of integer that I want to ensure increment operations happening thread-safe, so I used std::vector<std::atomic<int>> after all parallel increments I need non-atomic vector std::vector<int>. Is there an efficient way to do so, without copying? The vector is very large and performance is very important.

推荐答案

在C ++中,原子操作是对象本身的属性,而不是对象的访问方式.就对象模型而言, atomic< int> int 没有真正的关系,只是您可以将一个转换为另一个.您不能将 atomic< int> 转换为 int ;您只能创建一个具有相同值的新对象.

In C++, atomic operations are a property of the object itself, not of how you access it. As far as the object model is concerned, atomic<int> has no real relationship to int save the fact that you can convert one to another. You cannot transform an atomic<int> into an int; you can only create a new object with the same value.

这篇关于将原子int的向量强制转换或转换为int的向量的有效方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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