You may experience a C-Runtime heap performance problem in a Visual C++ application that is running on Windows 2000 or on Windows XP (323635)
The information in this article applies to:
- Microsoft Windows XP Professional
- Microsoft Windows 2000
- Microsoft Windows NT 4.0
- Microsoft Visual C++ 2005 Express Edition
- Microsoft Visual C++ .NET (2003)
- Microsoft Visual C++ .NET (2002)
- Microsoft Visual C++, 32-bit Editions 6.0
This article was previously published under Q323635 SYMPTOMS Under stress conditions that involve heavy memory use, a
program that was written in Visual C++ may perform better on a computer that is running
Microsoft Windows NT 4.0 than on a computer that is running Microsoft Windows 2000 or Microsoft Windows XP.
When you start the program, it seems to have similar or better
performance on a computer running Windows 2000 or Windows XP, and then, after
physical memory (RAM) is exhausted, the memory manager starts to use the
pagefile. When this occurs, the program on the computer running Windows 2000 or
Windows XP may slow down compared to the same program on the computer running
Windows NT 4.0. When you view the Task Manager on the computer running Windows
2000 or Windows XP, the CPU usage may peak at 100 percent. CAUSE Typically, programs that are written in Visual C++ make
allocations through the C-Runtime (CRT). These allocations are handled
differently on a computer running Windows NT 4.0 than on a computer running
Windows 2000 or Windows XP. When the CRT detects that the program is running on
Windows NT 4.0, it uses its own small-block heap for small allocations. The CRT
does this to increase heap performance on Windows NT 4.0.
In Windows
2000 and Windows XP, the heap manager has been improved so that the CRT does
not need the small-block heap. On a computer running Windows 2000 or Windows
XP, the CRT sends all of the allocations to the default process heap. However,
under stress conditions, the use of the small-block heap on a computer running
Windows NT 4.0 may cause memory operations to be more efficient than the same
operations on a computer running Windows 2000 or Windows XP.
RESOLUTION You can force the use of the small-block heap on all
operating systems. To do this, add the following code to the beginning of your
program:
#include <malloc.h>
int sbh = _set_sbh_threshold(1016);
This code sets the small-block heap threshold to 1016 bytes, so that
any allocations that have a size equal to or less than 1016 bytes are allocated
on the private CRT heap. 1016 is the hard-coded value that MAX_ALLOC_DATA_SIZE is set to in the CRT source. The CRT uses MAX_ALLOC_DATA_SIZE as the default value to initialize the small-block heap on a
computer running Windows NT 4.0. Note There may be other differences between operating systems that
cause performance variations. This is only one potential cause. STATUSThis
behavior is by design.REFERENCES For more information about memory and performance, visit
the following Microsoft Web site:
Modification Type: | Major | Last Reviewed: | 1/6/2006 |
---|
Keywords: | kbprb KB323635 kbAudDeveloper |
---|
|