1

This question isn't really specific, but more general.

So let's say I have program A and program B which both use the same dynamic library for example apple.dll. And both programs would use the same instance of the dynamic library so changes made with one program in the .dll would also be seen by the other program. So when for example I add two apples in program A, then if I get apples in program B it should return 2.

See illustration below

illustration

So my question is how to achieve this behavior (if it is even possible) and if one solution is cross platform.

Maratonec
  • 73
  • 9
  • What changes could either program make to the .dll? – paolo Apr 21 '22 at 13:19
  • @paolo Well for example the variable apple as seen in the in the illustration can be change with function by both programs. – Maratonec Apr 21 '22 at 13:21
  • 1
    What if a third or tenth program starts using the dll? What if you have two separate sets of programs? Please describe the intended behaviour. – Yunnosch Apr 21 '22 at 13:23
  • 2
    The picture is not really readable for me. However (I may be wrong on this) isn't the ".dll memory", including its global variables, owned by the program's process? – paolo Apr 21 '22 at 13:25
  • @paolo Oh sorry should have made it in higher resolution. I know it is owned by the programs process normally, but I want to know if there is way around this. – Maratonec Apr 21 '22 at 13:29
  • 1
    Firstly, there is nothing in C++ itself that allows you to do that. However, you may be able to use shared memory, which every OS out there supports, Windows included. Use that as a search term, I believe there even is something in Boost, for example. – Ulrich Eckhardt Apr 21 '22 at 13:31
  • Does this answer your question? [Global variable in shared library](https://stackoverflow.com/questions/30695700/global-variable-in-shared-library) – Lala5th Apr 21 '22 at 13:33
  • @UlrichEckhardt Thank you. What you suggested may be the only real solution as when I was searching I also found only this. – Maratonec Apr 21 '22 at 13:36
  • @Lala5th not really – Maratonec Apr 21 '22 at 13:37

0 Answers0