|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.|
CustomString Sample: Demonstrates Custom Memory Allocators for CStringT
The CustomString sample shows how to use a custom memory allocator for CStringT to improve performance in a multithreaded application. The sample application replaces carriage return/line feed pairs in a set of text files with a single carriage return, processing multiple files simultaneously on different threads.
This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.
Building and Running the Sample
To build and run this sample
Open the solution file CustomString.sln.
From the Build menu, click Build Solution.
To run the sample from a command prompt, type CustomString *.txt. The sample will find all files in the current directory with ".txt" as the file extension and will create a copy of each file with ".utxt" as the file extension. The new files will have all CR/LF pairs replaced with a single CR.
To run the sample from within Visual Studio, right-click the solution and click Properties on the shortcut menu. Under Configuration Properties. select Debugging, and set the command-line argument property to "*.txt" for the correct configuration.
Classes and Keywords
This sample uses the following classes:
IAtlStringMgr; CWin32Heap; CAtlStringMgr; CStringT
This sample uses the following keywords:
CBitmap::LoadBitmap; CEdit::Clear; CEdit::GetLineCount; CEdit::LineIndex; CEdit::LineLength; CEdit::ReplaceSel; CEdit::SetSel; CFileDialog::DoModal; CFileDialog::GetPathName; CGdiObject::DeleteObject; CSpinButtonCtrl::GetBuddy; CString::GetBufferSetLength; CString::GetLength; CString::Left; CString::LoadString; CString::ReleaseBuffer; CWinApp::LoadIcon; CWnd::GetClientRect; CWnd::GetWindowRect; CWnd::SetWindowPos; CWnd::SetWindowText; DeleteItem; CWnd::DestroyWindow; CWnd::EnableWindow; GetCursorPos; GetDlgItem; GetParent; GetWindowLong; GetWindowRect; InvalidateRect; LoadIcon; MAKELONG; MessageBeep; ReleaseCapture; ScreenToClient; SetCapture; SetWindowLong; SetWindowPos; UpdateWindow; WindowProc; mbstowcs; rand; srand; time; wsprintf