### Improve Memory Management

Because C++ objects are often allocated from the heap and have limited scope, memory use in C++ programs affects performance more than in C programs. Points below that apply specifically to C++ are identified by

- The run-time library automatically creates a pool for the default run-time heap for objects 1 to 512 bytes in size, and aligns them on 8-byte boundaries. You can reduce wasted memory by changing the default setting of _upool() from _ALIGN8 to _ALIGN4, then call _uflush to return unused storage to the heap.
  Do not change the default if the objects contain double-precision floating-point variables or arrays, since alignment on an 8-byte boundary can improve performance when accessing these objects.
- When you declare or define structures or C++ classes, take into account the alignment of data types. Declare the largest members first to reduce wasted space between members and to reduce the number of boundaries the compiler must cross. The alignment is especially important if you pack your structure or class.
- After freeing or reallocating storage, periodically call _heapmin to release unused storage to the operating system and reduce the working set of your program. A reduced working set causes less swapping of memory to disk. Experiment to determine how often you should call _heapmin.
- Tailor your own new and delete operators.
- Allocate memory for a class before it is required.
- Ensure that objects that are no longer needed are freed or otherwise made available for reuse. One way to do this is to use an object manager. Each time you create an instance of an object, pass the pointer to that object to the object manager. The object manager maintains a list of these pointers. To access an object, you can call an object manager member function to return the information to you. The object manager can then manage memory usage and object reuse.
- Avoid copying large, complex objects.

Optimize Your Application
Memory Management Functions
Data Mapping

Improve Allocation of Storage