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.
Security Note: |
---|
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. |
To get samples and instructions for installing them:
On the Visual Studio Help menu, click Samples.
For more information, see Visual Studio Samples.
The most recent version and complete list of samples is available online from the Visual Studio 2008 Samples page.
You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied into a folder under \Program Files\Visual Studio 9.0\Samples\. For Express editions of Visual Studio, all samples are located online.
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