| View previous topic :: View next topic |
| Author |
Message |
DaveR Valued Contributor


Joined: 03 Sep 2005 Posts: 413 Location: Australia
|
Posted: Mon Jan 02, 2006 3:20 am Post subject: When to loadlib and freelib? |
|
|
If repeatedly using the same dll throughtout a program is it best to:
a.) loadlib at the start of the program, and then freelib when the program closes?
or
b.) loadlib and freelib each time the dll is needed?
What are the advantages/disadvantages to each method? _________________ cheers
Dave |
|
| Back to top |
|
 |
trapper Contributor


Joined: 28 Jan 2005 Posts: 112 Location: Brisbane, Australia
|
Posted: Mon Jan 02, 2006 4:17 am Post subject: Re: When to loadlib and freelib? |
|
|
| DaveŽ wrote: | If repeatedly using the same dll throughtout a program is it best to:
a.) loadlib at the start of the program, and then freelib when the program closes?
or
b.) loadlib and freelib each time the dll is needed?
What are the advantages/disadvantages to each method? |
I'm not sure which is ideal but I do a), except that calling certain DSUs unloads some DLLs (eg. one I repeatedly use calls and unloads user32.dll), so after a call to that DSU I do a loadlib of user32.dll. Given that, perhaps b) would be better.
Cheers... _________________ John Trappett |
|
| Back to top |
|
 |
DaveR Valued Contributor


Joined: 03 Sep 2005 Posts: 413 Location: Australia
|
Posted: Mon Jan 02, 2006 5:01 am Post subject: |
|
|
I was using method B, but I was getting occasional access violation errors. I deduced that certain rapid user actions were trying to loadlib before the previous freelib had finished freeing the dll.
I think changing to method A has fixed it. <insert fingers crossed emoticon here> _________________ cheers
Dave |
|
| Back to top |
|
 |
PGWARE Web Host

Joined: 29 Dec 2001 Posts: 1565
|
Posted: Tue Jan 03, 2006 4:31 am Post subject: |
|
|
| I'd say it depends on the usage of the library. If the library will be accessed dozens of times in a program (say for instance in a loop) then it may be better off to loadlib and freelib one time only (start and end of application). If the library will be used seldom in the program it may be better to just call the library on the fly and then immediately close when done - this conserves memory and cpu usage. |
|
| Back to top |
|
 |
|