DLLs and PB internal object management

Everything else that doesn't fall into one of the other PB categories.
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

DLLs and PB internal object management

Post by Inf0Byt3 »

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?
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: DLLs and PB internal object management

Post by srod »

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! :)
I may look like a mule, but I'm not a complete ass.
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Re: DLLs and PB internal object management

Post by Inf0Byt3 »

Thank you for the information, it now all makes sense. Dunno what i was thinking :lol:.
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Re: DLLs and PB internal object management

Post by Num3 »

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... :lol: :lol:
Post Reply