How to overload new to reduce memory fragmentation (139638)
The information in this article applies to:
- Microsoft Visual C++ 2.0
- Microsoft Visual C++ 2.1
- Microsoft Visual C++ 2.2
- Microsoft Visual C++ 4.0
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
This article was previously published under Q139638 SUMMARY
Providing a dedicated heap by overloading new and delete for a class can
significantly reduce memory fragmentation. Any class that is frequently
instantiated using new is a candidate for providing a dedicated heap.
This method works best when many instances of a class are used in close
time proximity but random order. For example, this method will work well
for a newly created list that is about to be sorted.
This method impairs performance where the use of instances of the class is
more time proximate to the use of other heap-allocated objects. For
example, this method would impair the performance of a scrolling, in-memory
view of rows read from a database.
There is no easy substitute for careful analysis of locality of reference,
where locality is gauged according to the page size used by the host
operating system's virtual memory management and time separation.
This technique should not be applied to a base class that can be or might
be derived from if data is to be added to the derived class.
Modification Type: | Major | Last Reviewed: | 5/26/2005 |
---|
Keywords: | kbtshoot kbcode kbCRT kbhowto kbLangCPP KB139638 kbAudDeveloper |
---|
|