Is it OK to use boost::shared ptr in DLL interface?

前端 未结 5 538
臣服心动
臣服心动 2021-01-04 19:21

Is it valid to develop a DLL in C++ that returns boost shared pointers and uses them as parameters?

So, is it ok to export functions like this?

1.) b         


        
5条回答
  •  囚心锁ツ
    2021-01-04 19:51

    Something to lookout for if you expose raw pointers from a dll interface. It forces you to use the shared dll CRT, memory allocated in one CRT cannot be deallocated in a different CRT. If you use the shared dll CRT in all your modules ( dll's & exe's ) then you are fine, they all share the same heap, if you dont you will be crossing CRT's and the world will meltdown.

    Aside from that issue, I agree with the accepted answer. The creation factory probably shouldn't define ownership & lifecycle management for the client code.

提交回复
热议问题