It is currently Sat Sep 26, 2020 12:04 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: When to free the memory, or another things?
PostPosted: Tue Jan 21, 2020 10:14 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Jan 22, 2016 5:33 pm
Posts: 129
Location: Spain
Thank you all for your answers, I will investigate a little more to see if I find a valid solution


Top
 Profile  
Reply with quote  
 Post subject: Re: When to free the memory, or another things?
PostPosted: Tue Jan 21, 2020 12:29 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Wed Oct 29, 2003 4:35 pm
Posts: 10589
Location: Beyond the pale...
Quote:
Both.

It has nothing to do with calling conventions, but it's clearly a bug in the threadsave library.


Nothing clear about it I'm afraid since Caronte3D has not indicated whether the dll has been compiled with the threadsafe switch and so this may not even be an issue. I'm not saying that there isn't a bug in the threadsafe lib, but not clear in this case whether this could be the root cause. Over to Caronte3D! :)

_________________
I may look like a mule, but I'm not a complete ass.


Top
 Profile  
Reply with quote  
 Post subject: Re: When to free the memory, or another things?
PostPosted: Tue Jan 21, 2020 1:23 pm 
Offline
User
User

Joined: Wed Feb 26, 2014 3:16 pm
Posts: 76
srod wrote:
Quote:
Both.

It has nothing to do with calling conventions, but it's clearly a bug in the threadsave library.


Nothing clear about it I'm afraid since Caronte3D has not indicated whether the dll has been compiled with the threadsafe switch and so this may not even be an issue. I'm not saying that there isn't a bug in the threadsafe lib, but not clear in this case whether this could be the root cause. Over to Caronte3D! :)


Indeed, I was only referring to my experiences.


Top
 Profile  
Reply with quote  
 Post subject: Re: When to free the memory, or another things?
PostPosted: Tue Jan 21, 2020 3:16 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3319
Location: Boston, MA
I experienced an x86 stdcall dll crash on calls to closelibrary() in detach().

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: When to free the memory, or another things?
PostPosted: Tue Jan 21, 2020 6:49 pm 
Offline
User
User

Joined: Wed Feb 26, 2014 3:16 pm
Posts: 76
skywalk wrote:
I experienced an x86 stdcall dll crash on calls to closelibrary() in detach().

If you mean that you call closelibrary in detach_process, then that's a no go.
See https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-entry-point-function

Quote:
The entry-point function should perform only simple initialization tasks. It must not call the LoadLibrary or LoadLibraryEx function (or a function that calls these functions), because this may create dependency loops in the DLL load order. This can result in a DLL being used before the system has executed its initialization code. Similarly, the entry-point function must not call the FreeLibrary function (or a function that calls FreeLibrary) during process termination, because this can result in a DLL being used after the system has executed its termination code.


Top
 Profile  
Reply with quote  
 Post subject: Re: When to free the memory, or another things?
PostPosted: Tue Jan 21, 2020 7:43 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Jan 22, 2016 5:33 pm
Posts: 129
Location: Spain
srod wrote:
Nothing clear about it I'm afraid since Caronte3D has not indicated whether the dll has been compiled with the threadsafe switch and so this may not even be an issue.

Yes, the dll has been compiled with the threadsafe switch because I create several threads from the dll.


Top
 Profile  
Reply with quote  
 Post subject: Re: When to free the memory, or another things?
PostPosted: Tue Jan 21, 2020 8:37 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3319
Location: Boston, MA
sq4 wrote:
skywalk wrote:
I experienced an x86 stdcall dll crash on calls to closelibrary() in detach().

If you mean that you call closelibrary in detach_process, then that's a no go.
See https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-entry-point-function
Thanks, I learned that the hard way. Dropped the closelibrary() calls and all good.
Quote:
The entry-point function should perform only simple initialization tasks. It must not call the LoadLibrary or LoadLibraryEx function...
But, the dll had to call load library :!: Not sure what they mean by that.

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: When to free the memory, or another things?
PostPosted: Wed Jan 22, 2020 12:11 am 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 6258
Location: Wales, UK
@skywalk

I think what MS are saying is that the DLL should not be loaded during the time the Program is started. It can be loaded later, on demand. Likewise, the DLL should not be closed or freed at the same time as the Program - so when the Program is closed, that needs careful management, it can't just be exited when WaitWindowEvent() = #PB_Event_CloseWindow for example. The snag is, most times you will only want to close the lib when the User wants to close the Program, so the Program needs to know if and when the DLL is fully released before closing itself.

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: When to free the memory, or another things?
PostPosted: Wed Jan 22, 2020 9:14 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Wed Oct 29, 2003 4:35 pm
Posts: 10589
Location: Beyond the pale...
Caronte3D wrote:
srod wrote:
Nothing clear about it I'm afraid since Caronte3D has not indicated whether the dll has been compiled with the threadsafe switch and so this may not even be an issue.

Yes, the dll has been compiled with the threadsafe switch because I create several threads from the dll.


In which case it looks like you have probably run up against the same bug/issue that sq4 has mentioned. You might want to try and remove the threadsafe option and employ your own thread protection mechanisms (mutex, semaphore etc.) The biggest problem might be avoiding the use of PB's string library as this is not threadsafe without the threadsafe compiler switch. Try and avoid using strings in the dll threads (main dll process is fine) - perhaps use memory buffers/pointers instead. I'm sure sq4 can advise given his experience with this issue.

_________________
I may look like a mule, but I'm not a complete ass.


Top
 Profile  
Reply with quote  
 Post subject: Re: When to free the memory, or another things?
PostPosted: Fri Jan 24, 2020 1:13 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Jan 22, 2016 5:33 pm
Posts: 129
Location: Spain
I use too much strings at the moment and I'm in a hurry to finish :? I will take a look again when finish this project.
Thanks!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 41 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye