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.
cmustaffAsked:
Who is Participating?
 
alexoConnect With a Mentor Commented:
Raymond, I guess I was too harsh, sorry, should get more sleep.  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.

Anyway, the complete answer is:
1. There is no INHERENT limit in Win32 regarding the number of loaded DLLs.
2. The number can be limited by available system resources (an article I provided a link to mentions ~500 in certain configurations).
3. The use of TLS by the DLLs can exhaust TLS indexes and effectively limit the number of loaded DLLs to 64.
0
 
nietodCommented:
You might want to try asking this in the windows topic area.  this is not really a C++ question.
0
 
rwilson032697Commented:
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.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
alexoCommented:
>> 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.
0
 
nietodCommented:
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?
0
 
nietodCommented:
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.
0
 
alexoCommented:
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

0
 
cmustaffAuthor Commented:
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
0
 
nietodCommented:
>>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.
0
 
rwilson032697Commented:
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.

0
 
nietodCommented:
>> 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.  
0
 
cmustaffAuthor Commented:
alexo's answer provided the clue that was needed to reset the run-time options in the
VC++ project studio settings.  Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.