开发者

Is c lib a static in c++ program?

I have a c lib, algo.lib, which I need to call in my c++ program. I realise that the variables in algo.lib is static, which creates problem for my c++ program, when I call algo.lib multiple times, or use threads to call algo开发者_如何学JAVA.lib concurrently.

For example, in algo.lib, there is a int a which is initiall set to 0. When I call algo.lib the first time, a will be set to 1000. But when I call algo.lib another time, I want the variables in algo.lib to be in the initial state, that is, a = 0 and not a = 1000.

Is it possible to make algo.lib to become object-oriented, so that when I call its function, it is created as an object and is set to its initial state? And after finish running algo.lib, this object is destroyed?


Yes, it is possible. If you rewrite it. If you only have the binary - then you cannot change this behavior. You can solve it by creating a separate executable that will do what you want with it and then exit, and pass the results back to the main program through some IPC. Basically - wrap it with your own implementation that will effectively initialize the library for each separate call.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜