Tips for Managing Dynamic Memory
The more you use the heap, the more fragmented it will get and the more slowly your program will run. If your program is supposed to run for hours or days at a time, you have to be careful. It's better to allocate all the memory you need when your program starts and then free it when the program exits, but that's not always possible. The CString class is a nuisance because it's constantly allocating and freeing little bits of memory.Don't forget to call _heapmin every once in a while if your program allocates blocks larger than the small-block heap threshold. And be sure to remember where heap memory comes from. You'd have a big problem, for instance, if you called HeapFree on a small-block pointer you got from new.Be aware that your stack can be as big as it needs to be. Because you no longer have a 64 KB size limit, you can put large objects on the stack, thereby reducing the need for heap allocations.Your program won't run at full speed and then suddenly throw an exception when Windows runs out of swap space. It will just slowly grind to a halt, making your customer unhappy. There's not much you can do except try to figure out which program is eating memory and why. Because the USER and GDI modules in Windows 95/98 still have 16-bit components, there is some possibility of exhausting the 64 KB heaps that hold GDI objects and window structures. This possibility is pretty remote, however, and if it happens, it probably indicates a bug in your program.