VS2010's concurency runtime and unbounded_buffer<shared_ptr<T>>, any pitfalls?

时光总嘲笑我的痴心妄想 提交于 2020-01-04 02:33:09

问题


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;

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.


回答1:


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

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

  2. 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.

  3. 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).



来源:https://stackoverflow.com/questions/10951549/vs2010s-concurency-runtime-and-unbounded-buffershared-ptrt-any-pitfalls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!