RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.
Create a Windows-based .NET application that loads, using Platform Invoke, an unmanaged User DLL that has global variables (e.g. large arrays) that occupy ~1 GB or more of memory.
[When loaded from unmanaged Windows application, the DLL may load successfully. But this issue involves loading from a .NET application such as written in C# or VB.NET.]
DLL fails to load, generating an error such as:
    "LoadLibrary failed! MyUser.dll"
Memory occupied by the .NET (C#, VB.NET, etc.) module is more than when compared to the VC++ module, due to the following reasons:
1. Managed module loads loads other managed system DLLs, in addition to the native system DLLs
   e.g.,
mscorlib, system.windows,forms, System, Â
mscorwks, system.drawing, mscorlib, system.data etc..  Â
2. Available memory has to be divided for managed and unmanaged modules.
3. Even if enough memory remains overall, this DLLÂ may not be loaded due to memory fragmentation, since a contiguous block would be required to allocate global variables.
In the first place, it is generally a bad programming design to request around ~1 GB or more of memory at a time. Following are ways that this problem may be overcome, but they are just temporary solutions:
1.   Consider using the
Low-fragmentation Heap (LFH)
(http://msdn2.microsoft.com/en-us/library/aa366750.aspx)
2.    Consider using theÂ
/3GB switch
(http://kbalertz.com/Feedback.aspx?kbNumber=328882)
to increase the user address space of the process.
3.    Consider compiling the application targeting a x64 or IA64 machine, as a much greater amount of user memory will be available.
MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALSâ€) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.
Article ID: 951949 - Last Review: April 18, 2008 - Revision: 1.1
APPLIES TO
- Microsoft .NET Framework 1.1
- Microsoft .NET Framework 2.0
- Microsoft .NET Framework 3.0
- Microsoft .NET Framework 3.5
- Microsoft Visual Studio .NET 2003 Academic Edition
- Microsoft Visual Studio .NET 2003 Professional Edition
- Microsoft Visual Studio .NET 2003 Enterprise Developer
- Microsoft Visual Studio .NET 2003 Enterprise Architect
- Microsoft Visual Studio 2005 Express Edition
- Microsoft Visual Studio 2005 Standard Edition
- Microsoft Visual Studio 2005 Professional Edition
- Microsoft Visual Studio 2005 Team Suite
- Microsoft Visual Studio 2008 Academic Edition
- Microsoft Visual Studio 2008 Standard Edition
- Microsoft Visual Studio 2008 Professional Edition
- Microsoft Visual Studio Team System 2008 Team Suite
| kbnomt kbrapidpub KB951949 |