I'm working these days on a program that uses plugins in DLL form. The framework seems to work fine except one thing. It seems that PureBasic dlls share the same object lists in memory. In other words if I execute the same plugin 2 times (with 2 different threads) then the second loaded DLL will know about the window in the first loaded DLL (they will share the same number/handle). So in the same process, a dll that is 'ran' twice (even if in different threads) makes the object lists 'collide' (i tested with fonts and windows so far). Shouldn't each DLL have it's own internal list of objects?
The big problem for me is that I wanted to make the program run multiple instances of the same plugin. Is there a way to bypass this limitation? Should I use #PB_Any for all windows, fonts, etc. that i use in plugins?
DLLs and PB internal object management
DLLs and PB internal object management
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
Re: DLLs and PB internal object management
Each dll does indeed use it's own process heap memory for such things. It is just that a dll is mapped into the loading process only once, regardless of how many threads use it's functions etc. So you are really mis-using the expression 'each dll'. Really, you are just talking about a single dll. Load the same dll 10 times from 10 threads within the same process and you will still only have one copy of the dll loaded (at least in the normal run of things). So in effect you are talking about a single program with multiple threads (forget the dll), each creating windows etc. In this case (as with the dll problem you have mentioned) all threads will share the same process memory for gadget# etc. as PB allocates a global block of heap memory for this.
And to be honest you can't really expect PB to create separate gadget lists etc. for multiple threads. Simply use #PB_Any as you've already remarked. You would be bonkers to code a dll without using #PB_Any!
And to be honest you can't really expect PB to create separate gadget lists etc. for multiple threads. Simply use #PB_Any as you've already remarked. You would be bonkers to code a dll without using #PB_Any!
I may look like a mule, but I'm not a complete ass.
Re: DLLs and PB internal object management
Thank you for the information, it now all makes sense. Dunno what i was thinking
.
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
-
Num3
- PureBasic Expert

- Posts: 2812
- Joined: Fri Apr 25, 2003 4:51 pm
- Location: Portugal, Lisbon
- Contact:
Re: DLLs and PB internal object management
Yeah, i noticed this too when i was trying to make a dll based program.
If i called my init function of dll 2 times it would crash, when trying to open the same window.
Oh well i ended up making just one executable...

If i called my init function of dll 2 times it would crash, when trying to open the same window.
Oh well i ended up making just one executable...
