|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
Memory Management and CStringT
Class CStringT is a template class used to manipulate variable-length character strings. The memory to hold these strings is allocated and released through a string manager object, associated with each instance of CStringT. MFC and ATL provide default instantiations of CStringT, called CString, CStringA, and CStringW, which manipulate strings of different character types. These character types are of type TCHAR, char, and wchar_t, respectively. These default string types use a string manager that allocates memory from the process heap (in ATL) or the CRT heap (in MFC). For typical applications, this memory allocation scheme is sufficient. However, for code making intensive use of strings (or multithreaded code) the default memory managers may not perform optimally. This topic describes how to override the default memory management behavior of CStringT, creating allocators specifically optimized for the task at hand.
- Implementation of a Custom String Manager (Basic Method)
- Avoidance of Heap Contention
- Implementation of a Custom String Manager (Advanced Method)
- CFixedStringT: An Example of a Custom String Manager