Link to home
Start Free TrialLog in
Avatar of cmustaff
cmustaff

asked on

Limit on number of DLLs that can be loaded

What is upper limit on the number of DLL's that can be loaded by an application? I keep hearing 64 DLL's is the limit but can not find any documentation to verify this.
Avatar of nietod
nietod

You might want to try asking this in the windows topic area.  this is not really a C++ question.
I am not aware of any limit.

The MSDN entry for Windows 95 system limitations does not mention any and I would be surprised if NT had any such limit.

Cheers,

Raymond.
>> I am not aware of any limit.
Raymond, the "comment" radio button was invented for exactly this purpose.  Locking questions with non-helpful answers or just opinions is unprofessional.

>> this is not really a C++ question.
Sorry, Todd, it is.  See explanation below.

cmustaff, the WIN32 architecture does not contain any limit for the number of DLLs.
However, the C/C++ run-time library (at least the one that comes with MS compilers, possibly others too) uses TLS to internally manage loaded DLLs.  Since it only allocates 64 DLL slots, it effectively limits you to 64 DLLs.  Note that an application that does not use TLS and does not include the C/C++ RTL can use more DLLs.

BTW, you may want to "reopen" the question since the currently pending answer by  rwilson is incorrect.
It thought that limit was 64 threads, not 64 DLLs.  (and 64 threads on win95 will practically kill the computer anyways)   What the heck does it need to do that depends on the number of DLLs?
Alex, are you sure you are right about this one?  Granted this is more your area of expertise than mine, but as I understand it, there are (at least) 64 TLS indexes.  That effectively limits you to 64 seperate cases of thread local storage per process.  Now some DLL's may use a TLS slot, like the run-time library, but I don't see any evidence that all will, so you would be limited to 64 DLLs that use TLS.  Now if the DLLs are staticaly linked to the run-time library each might use a TLS slot, but if they are dynamically linked (which is better anyways) they should not.  At least as far as I can tell.
A bit more checking reveals a way around the limit: don't use the "multithreaded DLL" RTL option.

References:
    http://www.dejanews.com/getdoc.xp?AN=292551568
    http://www.dejanews.com/getdoc.xp?AN=411286011

Avatar of cmustaff

ASKER

A sample executable built with the debug multi-threaded option
and a statically linked C/C++ RTL was used to load as many DLLs
as possible.  When attempting to load the 65th DLL, the following
MessageBox was displayed.

"Initializatoion of a Dynamic Link Library, ..., failed.
 The process is terminating abnormally".

Changing the "Use run-time library" list option in Project Settings
to either of the following allowed the 64 DLL limit to be exceeded.

1. multi-threaded dynamically linked C/C++RTL
2. single-threaded statically linked C/C++ RTL
>>1. multi-threaded dynamically linked C/C++RTL
That works because there is only one copy of the run-time library being loaded, so it uses only one TLS slot.  (That is what I suggested above.)
>> 2. single-threaded statically linked C/C++ RTL
That works because although there are multiple copies of the run-time library loaded, tnone of them use any TLS slots.
alexo - I take your point re: the comment option. However this was in fact the answer to his question (as you point out :-).

If you read his question carefully this will be apparent. I believe my answer stands (re the original question) All you have pointed out is that in some special circumstances there is a 64 DLL limit. Had cmustaff (a staff member at CMU???) pointed out he(?) had in fact reached the limit he quoted in the circumstances he was using this would have permitted the more specialised answer now available to be formulated.

Cheers,

Raymond.

ASKER CERTIFIED SOLUTION
Avatar of alexo
alexo
Flag of Antarctica image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> However, seems to me that "I am not aware of any
>>   limit" and "I would be surprised" fit the category of opinions more than answers
I would have to agree.  
alexo's answer provided the clue that was needed to reset the run-time options in the
VC++ project studio settings.  Thanks