Any improvements on the GCC/Windows DLLs/C++ STL front?

北战南征 提交于 2019-12-02 00:58:53

The general problem you're running into is that C++ was never really meant as a component language. It was really designed to be used to create complete standalone applications. Things like shared libraries and other such mechanisms were created by vendors on their own. Think of this example: suppose you created a C++ component that returns a C++ object. How is the C++ component know that it will be used by a C++ caller? And if the caller is a C++ application, why not just use the library directly?

Of course, the above information doesn't really help you.

Instead, I would create the shared libraries/DLLs such that you follow a couple of rules:

  1. Any object created by a component is also destroyed by the same component.
  2. A component can be safely unloaded when all of its created objects are destroyed.

You may have to create additional APIs in your component to ensure these rules, but by following these rules, it will ensure that problems like the one described won't happen.

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