VS2010的concurency运行时和unbounded_buffer< shared_ptr< T>,任何陷阱? [英] VS2010's concurency runtime and unbounded_buffer<shared_ptr<T>>, any pitfalls?

查看:351
本文介绍了VS2010的concurency运行时和unbounded_buffer< shared_ptr< T>,任何陷阱?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从dll传递堆分配的对象。显然,内存必须正确管理。有没有人看到我设计的以下狡猾方案的问题:

I want to pass heap-allocated objects from a dll. Obviously, memory must be managed correctly. Does anyone see a problem with the following cunning scheme I devised:

unbounded_buffer<shared_ptr<T>> buf;



我知道shared_ptr隐藏了一个包含对象的删除器,所以单独使用它跨越dll边界

I am aware that shared_ptr stashes away a deleter for the contained object, so using it alone across dll boundaries shouldn't be a problem.

推荐答案

这是我从MSFT收到的关于这个问题:

Here's what I received from MSFT regarding the issue:


  1. 是的,您可以使用由CreateThread手动创建的线程上的消息块(如unbounded_buffer)。

  1. Yes, you can use the message blocks (like unbounded_buffer) on thread that are manually created with CreateThread.

消息不能遍历dll边界,因为它的分配和删除必须发生在同一dll中。一些消息块(如变换器)分配新消息。所以他们也遭受同样的问题。 unbounded_buffer>是完全可以使用,除非它不解决上述问题。类型模板参数指消息中的有效内容类型(即消息)。它不是信封的类型。

Messages cannot traverse dll boundaries in that its allocation and deletion must occur in the same dll. Some message blocks like transformer allocates new messages. So they suffer from the same issue as well. unbounded_buffer> is perfectly fine to use except it doesn't solve the above issue. The type template argument refers to the payload type in the message (that is message). It is not the type of the envelope.

在稳定状态下,数据流网络的吞吐量非常好。性能损失的主要来源是在建立网络时链接和取消链接消息块。在Visual Studio 2010中,消息启动命令(如send和asend)会遭受此性能损失。我们在即将发布的Visual Studio中解决了这个问题。没有计划将修复端口到VS2010。一种潜在的解决方法是实现始终连接到数据流网络的简单ISource消息块。使用此块向网络发起消息(Agents.h中的_Originator是ISource块的示例)。

In the steady state the throughput of a data flow network is very good. The main source of performance penalty is the linking and unlinking of message blocks when a network is being setup. In Visual Studio 2010 the message initiation commands such as send and asend suffered from this performance penalty. We have addressed this issue in the upcoming release of Visual Studio. There is no plan to back port the fix to VS2010. A potential workaround is to implement a simple ISource message block that is always connected to the dataflow network. Use this block to initiate messages into the network (The _Originator in agents.h is an example for an ISource block).

这篇关于VS2010的concurency运行时和unbounded_buffer&lt; shared_ptr&lt; T&gt;,任何陷阱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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