Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top