| title | CFixedStringT Class | |||
|---|---|---|---|---|
| ms.date | 03/27/2019 | |||
| f1_keywords |
|
|||
| helpviewer_keywords |
|
|||
| ms.assetid | 6d4171ba-3104-493a-a6cc-d515f4ba9a4b |
This class represents a string object with a fixed character buffer.
template<class StringType, int t_nChars>
class CFixedStringT : private CFixedStringMgr, public StringType
StringType
Used as the base class for the fixed string object and can be any CStringT-based type. Some examples include CString, CStringA, and CStringW.
t_nChars
The number of characters stored in the buffer.
| Name | Description |
|---|---|
| CFixedStringT::CFixedStringT | The constructor for the string object. |
| Name | Description |
|---|---|
| CFixedStringT::operator = | Assigns a new value to a CFixedStringT object. |
This class is an example of a custom string class based on CStringT. Although similar, the two classes differ in implementation. The major differences between CFixedStringT and CStringT are:
-
The initial character buffer is allocated as part of the object and has size t_nChars. This allows the
CFixedStringobject to occupy a contiguous memory chunk for performance purposes. However, if the contents of aCFixedStringTobject grows beyond t_nChars, the buffer is allocated dynamically. -
The character buffer for a
CFixedStringTobject is always the same length ( t_nChars). There is no limitation on buffer size forCStringTobjects. -
The memory manager for
CFixedStringTis customized such that sharing of a CStringData object between two or moreCFixedStringTobjects is not allowed.CStringTobjects do not have this limitation.
For more information on the customization of CFixedStringT and memory management for string objects in general, see Memory Management and CStringT.
IAtlStringMgr
StringType
CFixedStringMgr
CFixedStringT
Header: cstringt.h
Constructs a CFixedStringT object.
CFixedStringT() throw();
explicit CFixedStringT(IAtlStringMgr* pStringMgr) throw();
CFixedStringT(const CFixedStringT<StringType, t_nChars>& strSrc);
CFixedStringT(const StringType& strSrc);
CFixedStringT(const StringType::XCHAR* pszSrc);
explicit CFixedStringT(const StringType::YCHAR* pszSrc);
explicit CFixedStringT(const unsigned char* pszSrc);
pszSrc
A null-terminated string to be copied into this CFixedStringT object.
strSrc
An existing CFixedStringT object to be copied into this CFixedStringT object.
pStringMgr
A pointer to the memory manager of the CFixedStringT object. For more information on IAtlStringMgr and memory management for CFixedStringT, see Memory Management and CStringT.
Because the constructors copy the input data into new allocated storage, you should be aware that memory exceptions may result. Some of these constructors act as conversion functions.
Reinitializes an existing CFixedStringT object with new data.
CFixedStringT<StringType, t_nChars>& operator=(
const CFixedStringT<StringType, t_nChars>& strSrc);
CFixedStringT<StringType, t_nChars>& operator=(const char* pszSrc);
CFixedStringT<StringType, t_nChars>& operator=(const wchar_t* pszSrc);
CFixedStringT<StringType, t_nChars>& operator=(const unsigned char* pszSrc);
CFixedStringT<StringType, t_nChars>& operator=(const StringType& strSrc);
pszSrc
A null-terminated string to be copied into this CFixedStringT object.
strSrc
An existing CFixedStringT to be copied into this CFixedStringT object.
You should be aware that memory exceptions may occur whenever you use the assignment operator because new storage is often allocated to hold the resulting CFixedStringT object.