Universal STL-Based Template String Class

C++硬核开发指南:从零搭建环境到现代特性实战 编程语言作为软件开发的基石,其设计哲学直接影响着系统性能与工程效率。C++以其独特的“零开销抽象”原则,在提供接近硬件底层的控制力与极致性能的同时,支持现代高级抽象,实现了性能与生产力的平衡。这一特性使其在游戏引擎、高频交易、操作系统内核等对性能有严苛要求的领域成为核心技术选型。理解C++的核心在于建立正确的计算机系统观,包括对象生命周期、内存模型及RAII(资源获取即初始化)资源管理范式。通过掌握智能指针、移动语义等现代C++特性,开发者能够有效规避内存泄漏、悬空指针等常见陷阱,构建出健壮且高效的系统。本 阅读详情
 

Environment: VC++ 6sp5, VC++ 7.1 (.NET 2003)

Contents

Shortcomings of Extant String Classes

There are two reasons that urged me to create one more string class, in spite of the fact that so many of them already exist. Let's consider the following scenarios:

  1. TCHAR-based application extensively using COM, the functions/interface methods of which are WCHAR-based.
  2. TCHAR-based application working with network protocols, which normally make use of ASCII.
  3. Passing strings across module borders (between an executable and a DLL or between DLLs). In this situation, strings are required to use some global memory allocator (such as GlobalAlloc, CoTaskMemAlloc, or VirtualAlloc).
  4. Necessity to have strings that are compared case-insensitively by default. Sometimes, it is desirable as well to compare case-sensitive strings in a case-insensitive manner and vice versa.
  5. Any combination of the previous scenarios or any situation when different kinds of strings must be used jointly.

MFC's CString in VC++ 6.0 is hard-coded as a TCHAR-based class, has no provisions to change its own allocator (C++ new/delete operators), and does not allow you to set its default case-sensitivity state (to perform a case-insensitive comparison, it is necessary to use the CompareNoCase method explicitly). Thus, it does not fit any of the above scenarios.

STL's basic_string template class is much more flexible in this respect and allows you to create any kind of the strings suitable for specific scenarios. This is done by supplying proper char_traits and/or allocator classes as its template arguments. However, there remains one big problem. All these individual basic_string-based classes cannot cooperate with each other because the compiler treats them as distinct ones. Besides, they cannot interact either with the CString class or with the _bstr_t one. As a result, incessant explicit type casts and c_str method invocations appear in the program.

The same problem takes place with ATL/MFC CStringT template class in VC++ 7.0/7.1 (NET/NET 2003). An instance of CStringA class cannot be used together with a CStringW variable without explicit cast.

Resolving this problem was the first reason to create one more string class. The other reason is the fact that all standard VC string classes have some lack of functionality. Thus, the string content manipulation and comparison methods of the CString class yield noticeably to their STL's counterparts (find, rfind, replace, find_first_of, find_first_not_of, find_last_of, and find_last_not_of). On the other hand, the basic_string class lacks many very handy CString's methods, such as LoadString, Format/FormatV, TrimLeft/TrimRight, SpanIncluding/SpanExcluding, Mid/Right/Left, and some other.

The BasicString template class presented here is derived from the STL's basic_string template, and fills the mentioned functionality gap by providing new constructors, CString-like methods, and some new methods, which are described in the following sections. Because the the styles of CString and basic_string method names are starkly different, all the methods ported from CString, as well as some new ones, have both MFC- and STL-style names.

The second version of the BasicString class, in addition to the mentioned problems, deals with performance issues caused by using the STL's basic_string class, which became more evident after I have migrated from VC++ 6.0 to VC++ 7.1. See the Changes in Version 2 section for more detailed information.

Main Features

  1. The BasicString template class is designed to provide full interactivity between objects of all string classes based on it.

    The full interactivity means that any operator or method of any BasicString-based class accepts arguments of any other BasicString-based type. Besides, these arguments can be raw character pointers of any type (both ASCII and Unicode). Such interactivity extends over the global binary operators ( +, ==, !=, <, >, <=, >= ), too.

    For more convenience, eight different string classes that cover the most frequently used string types are typedefed in the "BasicString.h" header. They are as follows (for each of them the following information is listed): a) the character type, b) case-sensitivity of the compare method and the relational and equality operators, c) allocator type):

    • AString—char, case-sensitive, standard C++ allocator;
    • IAString—char, case-insensitive, standard C++ allocator;
    • GAString—char, case-sensitive, global COM-compliant allocator;
    • GIAString—char, case-insensitive, global COM-compliant allocator;
    • WString—wchar_t, case-sensitive, standard C++ allocator;
    • IWString—wchar_t, case-insensitive, standard C++ allocator;
    • GWString—wchar_t, case-sensitive, global COM-compliant allocator;
    • GIWString—wchar_t, case-insensitive, global COM-compliant allocator;

    Their TCHAR-based analogs are typedef'ed as well. They are:

    • String;
    • IString;
    • GString;
    • GIString;

    Additionally, the BasicString-based classes are fully interactive with the basic_string-based classes derived from the same char trait and allocator templates. For convenience, the typedefs of eight such basic_string-based classes are supplied. They are named in the same manner as the BasicString-based ones:

        AStdString (the same as STL's string class), IAStdString,
                                                     GAStdString,
                                                     GIAStdString
        WStdString (the same as STL's wstring class), IWStdString,
                                                      GWStdString,
                                                      GIWStdString
    
    and their TCHAR-based analogs:
        StdString, IStdString, GStdString, GIStdString.
  2. The full interactivity covers the _bstr_t and CString/CStringT classes as well. The corresponding code is compiled only if the project uses them. So, the "BasicString.h" header should be included after the <comdef.h> or <afx.h> headers. To support such functionality constructors, assignment operators, operators of conversion to _bstr_t and CString, and all binary operators (+, ==, !=, <, >, <=, >=) have been properly overloaded.

    The only known inconvenience is the impossibility to assign an object of a BasicString-based class to an object of the _bstr_t or CString type. The reason of such a behaviour is the fact that _bstr_t and CString are unaware of the BasicString class' existance, and consequently do not supply proper assignment operators. This hitch can be easily worked around by explicitly casting to the LPCWSTR or LPCTSTR as in the following example:

        String  str = _T("Test");
        _bstr_t bstr(str);      // OK
        bstr = (LPCWSTR)str;    // explicit conversion required
    
  3. Operators of conversion to the LPCSTR and LPCWSTR (and hence to the LPCTSTR) as well as the c_strA(), c_strW(), and c_strT() methods have been provided. They all return either the pointer to the object's own character sequence (if cast to the object's character type requested) or to the internally allocated buffer.

    Because the BasicString class derives from the basic_string, the destructor of which is non-virtual, the BasicString's destructor may not be called at some well-known circumstances. But, owing to the fact that the BasicString class does not have its own members and uses a special technique when allocating buffers to place converted strings, not calling its destructor does not cause any memory leaks.

    Yet, it must be assumed that pointers returned by the conversion operators and methods are temporary and can be invalidated by any subsequent non-const operation with the object that produced them (including, of course, its destruction, both implicit and explicit).

    Based on this functionality, the set of macros for in-place ASCII/Unicode conversion has been implemented:

        ToStr (str)     // str -> TCHAR*
        ToWstr (str)    // str -> wchar_t*
        ToAstr (str)    // str -> char*
    
    Here, the str argument can be char*, wchar_t*, or any kind of a string class. The pointers returned by these macros are temporary, so their use is limited to the function call argument lists or the inside of expressions they are used in.

    The second version of the BasicString class allows you to easily extend the functionality of these macros. See the Changes in the version 2 section for more detailed information.

  4. Loading strings from resources have been implemented. This is done either by means of constructor accepting raw character string pointers in the same manner as in the CString class:
        String    str((LPCTSTR)IDS_TEST);
    
    or by means of two STL-style methods with two their MFC-style analogs:
        bool  load ( HINSTANCE hInst, UINT nID );
        bool  load ( UINT nID );
    
        BOOL  LoadString ( HINSTANCE hInst, UINT nID );
        BOOL  LoadString ( UINT nID );
    
    The method globally changing the module handle that is used to locate resources is supplied as well:
        HINSTANCE  SetResourceHandle ( HINSTANCE hInst )
    By default, the handle of the EXE module is used to load strings. Therefore, the SetResourceHandle method should be used in DLLs to set the DLL's handle as a source of resources.

    Based on this functionality, three macros for in-place conversion from the resource ID to the raw character string pointers of different character types has been implemented:
        ResToStr (nID)
        ResToWstr (nID)
        ResToAstr (nID)
    
    The pointers returned by these macros are temporary, so their use is limited to the function call argument lists or the inside of expressions they are used in.

  5. Direct access to the internal string buffer is supported by means of two STL-style methods and two their MFC-style analogs:
        _E* get_buf ( size_type _Len = -1 );
        void  set_buf ( size_type _Len = -1 );
    
        _E* GetBuffer ( int nBufLen = -1 );
        void  ReleaseBuffer ( int nNewLen );
    
    Their functionality is the same as their CString counterparts have, with two following minor improvements:

    • The get_buf and GetBuffer methods can be called without a length parameter, in which case the current string length is used as the buffer size;
    • Debug versions of the set_buf and ReleaseBuffer methods perform the check of overwriting the allocated buffer boundaries. If such overwriting is detected, they assert.

  6. BSTR allocation methods analogous to those of CString class have been added. They are:
        BSTR  AllocSysString () const;
        BSTR  SetSysString ( BSTR* pbstr ) const;
    
    and their STL-style analogs:
        BSTR  bstr () const;    // the same as AllocSysString
        BSTR  realloc_bstr ( BSTR* pbstr ) const;
                                // the same as SetSysString
    
    These methods are compiled only if OLE automation headers have been included before the "BasicString.h" header file.

  7. Printf-like formatting has been implemented (using CRT library support). The following STL- and MFC-style methods do this:
        void __cdecl  printf ( const BasicString& _Fmt, ... );
        void __cdecl  printf ( unsigned int _FmtID, ... );
        void  vprintf ( const BasicString& _Fmt, va_list _args );
        void  vprintf ( unsigned int _FmtID, va_list _args );
    
        void __cdecl  Format ( const BasicString&
                                     strFormat, ... );
        void __cdecl  Format ( UINT nFormatID, ... );
        void  FormatV ( const BasicString& strFormat,
                                           va_list _args );
        void  FormatV ( UINT nFormatID, va_list _args );
    
  8. Constructing strings from GUIDs by means of the following constructor has been implemented:
        BasicString ( const GUID& );
    as well as assigning a GUID to the string:
        BasicString& operator = ( const GUID& );
    Additionally, the set of macros for in-place conversion from GUID to raw character string pointers and vice versa has been provided:
        GuidToStr (guid)
        GuidToWstr (guid)
        GuidToAstr (guid)
    
    The pointers returned by these macros are temporary, so their use is limited to the function call argument lists or the inside of expressions they are used in.

    To retrieve GUID from its text representation the following methods can be used:
        GUID  guid ( size_type _Pos = 0 ) const;
        GUID  GetGuid ( size_type _Pos = 0 ) const;
              // the same as guid(_Pos)
    
    GUID representation must start at the position specified by the _Pos argument. If there is no GUID at this position, GUID_NULL will be returned.

    If the string contains a GUID somewhere inside it, it is possible to find its start position by using the following method:
        size_type  find_guid ( size_type _Pos = 0 ) const;
        size_type  FindGuid  ( size_type _Pos = 0 ) const;
    
    The _Pos argument specifies the search start position. If there is no GUID found, the npos value (-1) will be returned.

    To allow for in-place conversion from any kind of a string to GUID, the following macro is supplied:
        StrToGuid (str)   // accepts any kind of a string or
                          // raw character pointers
    
  9. STL's comparison capabilities have been extended in the following ways. First, as it was described above, there are different classes (such as String and IString), whose relational and equality operators (==, != <, >, <=, >=) and compare method are by default always case sensitive or insensitive. The MFC-style Compare method added to the BasicString class inherits the behaviour of the compare method.
        int  Compare ( const BasicString& _S ) const;
             // restricted version of STL's compare method
    
    But, sometimes it could be handy to coerce case sensitivity or insensitivity of a comparison operation independently on the string class type. For this purpose, the following STL- and MFC-style methods have been added:
        int  cmp_case ( const BasicString& _S ) const;
             // always case-sensitive comparison
        int  cmp_no_case ( const BasicString& _S ) const;
             // always case-insensitive comparison
    
        int  CompareCase ( const BasicString& _S ) const;
             // the same as cmp_case
        int  CompareNoCase ( const BasicString& _S ) const;
             // the same as cmp_no_case
    
    Note   While using relational and equality operators (==, != <, >, <=, >=) with both operands being BasicString objects, the case-sensitivity of the operation is determined by the left operand. However, if one of the operands is of a raw character pointer (char* or wchar_t*), _bstr_t, or CString type, the case-sensitivity of the operation is determined by the BasicString object independently on its position. Thus in the following example:
        String str   = _T("string");
        IString stri = _T("String");
        bool b1      = str == stri;
        bool b2      = stri == str;
        bool b3      = _T("String") == stri;
        bool b4      = stri == _T("String");
    
    b1 becomes false, and b2, b3, and b4 become true.

  10. The CString-like Find, ReverseFind, and FindOneOf methods have been added. They all have been extended to support the second parameter specifying the start position. Besides, the ReverseFind method has been overloaded to support the string argument (CString supports TCHAR only). At last, the FindOneNotOf, FindLastOf, and FindLastNotOf methods have been added. Here are their prototypes:
        size_type Find ( _E _C, size_type _Pos = 0 ) const;
        size_type Find ( const BasicString& _S,
                  size_type _Pos = 0 ) const;
        size_type ReverseFind ( _E _C, size_type _Pos = npos )
                  const;
        size_type ReverseFind ( const BasicString& _S,
                  size_type _Pos = npos ) const;
        size_type FindOneOf ( const BasicString& _CharSet,
                  size_type _Pos = 0 ) const;
        size_type FindOneNotOf ( const BasicString& _CharSet,
                  size_type _Pos = 0 ) const;
        size_type FindLastOf ( const BasicString& _CharSet,
                  size_type _Pos = npos ) const;
        size_type FindLastNotOf ( const BasicString& _CharSet,
                  size_type _Pos = npos ) const;
    
    Yet, the native STL's methods, that have been used to implement the preceding ones, have much broader functionality than their MFC's counterparts. These methods are (for those unfamiliar with STL): find, rfind, find_first_of, find_first_not_of, find_last_of, and find_last_not_of.

  11. The CString-like SpanIncluding, SpanExcluding, TrimLeft, TrimRight, and their STL-style counterparts have been implemented:
        BasicString substr_of ( const BasicString& _CharSet )
                    const;
        BasicString substr_not_of ( const BasicString& _CharSet )
                    const;
    
        BasicString SpanIncluding ( const BasicString& _CharSet )
                    const;
        BasicString SpanExcluding ( const BasicString& _CharSet )
                    const;
    
    
        void  trim ( _E _C );
        void  trim ( const BasicString& _CharSet = sm_SpaceSym );
        void  rtrim ( _E _C );
        void  rtrim ( const BasicString& _CharSet =
              sm_SpaceSym );
    
        void  TrimLeft ( _E _C );
        void  TrimLeft ( const BasicString& _CharSet =
              sm_SpaceSym );
        void  TrimRight ( _E _C );
        void  TrimRight ( const BasicString& _CharSet =
              sm_SpaceSym );
    
  12. As in CString, the FormatMessage API helpers have been included into the BasicString class. Comparing to MFC two new overloads of the FormatMessage method has been added. They accept the va_list argument list as their second parameter.
        void __cdecl format_msg ( unsigned int _FmtID, ... );
        void __cdecl format_msg ( const _E* _Fmt, ... );
        void  vformat_msg ( unsigned int _FmtID, va_list _Args );
        void  vformat_msg ( const _E* _Fmt, va_list _Args );
    
        void __cdecl FormatMessage ( UINT _FmtID, ... );
        void __cdecl FormatMessage ( const _E* _Fmt, ... );
        void FormatMessageV ( UINT _FmtID, va_list _Args );
        void FormatMessageV ( const _E* _Fmt, va_list _Args );
    
    One more major improvement is the FormatSystemMessage and FormatModuleMessage methods, which format messages that reside in the system resource tables or in a module resources correspondingly. For example, the FormatSystemMessage method can be used to obtain text descriptions for the results of GetLastError or error codes returned by COM objects.
        void  format_sys_msg ( DWORD _MsgCode, ... );
        void  vformat_sys_msg ( DWORD _MsgCode, va_list _Args );
        void  format_mod_msg ( HMODULE hInst,
              DWORD _MsgCode, ... );
        void  vformat_mod_msg ( HMODULE hInst, DWORD _MsgCode,
              va_list _Args );
    
        void  FormatSystemMessage ( DWORD _MsgCode, ... );
        void  FormatSystemMessageV ( DWORD _MsgCode,
              va_list _Args );
        void  FormatModuleMessage ( HMODULE hInst,
              DWORD _MsgCode, ... );
        void  FormatModuleMessageV ( HMODULE hInst,
              DWORD _MsgCode, va_list _Args );
    
  13. In-place character case conversion methods have been implemented. They are:
        void  to_upper ();
        void  to_lower ();
        void  MakeUpper ();
        void  MakeLower ();
    
  14. CString-like methods Mid, Right, and Left, that simply map to the native STL's substr method, have been added:
        BasicString  Mid ( size_type _Pos, size_type _N )  const;
        BasicString  Right ( size_type _N )  const;
        BasicString  Left ( size_type _N )  const;
    
    as well as the GetLength, IsEmpty, Insert, Delete, and Replace ones:
        BasicString&  Insert ( size_type _Pos, _E _C )
        BasicString&  Insert ( size_type _Pos,
                      const BasicString& _S )
        BasicString&  Delete ( size_type _Pos, size_type _N = 1 )
        BasicString&  Replace ( _E chOld, _E chNew )
        BasicString&  Replace ( const BasicString& strOld,
                      const BasicString& strNew )
    
    Note, that unlike their CString counterparts, the Insert, Delete, and Replace methods return not the new string length, but the reference to the string itself. This helps to build the nested string modification clauses, while the length of the resulting string is still available through the length method without any performance penalties.

Changes in Version 2

As I noted at the beginning of the article, after I migrated to VC++ 7.1 I was terrified by inefficiency of Microsoft's basic_string implementation. Implementation in VC++ 6.0 is by far not optimal as well, but it is much better than what VC++ 7.1 offers now. Let's shortly consider the flaws.

In VC++ 6.0, basic_string supports reference counting, but keeps a DWORD of string length and a DWORD of allocated string buffer size in each instance of a string object instead of keeping them only in the shared memory block together with reference count (as, for example, CString does).

Another space waste is allocator, which is a member of basic_string. Therefore, even the standard STL's allocator that has no members takes a DWORD in the string object storage. If allocator were a base class, the compiler could use empty base optimization (EBO) to not allot the memory for it at all.

As the net result, each string object in VC++ 6.0 takes four DWORDs of storage, while it could take only one DWORD (to keep a pointer to the shared memory block).

In VC++ 7.1, basic_string DOES NOT support reference counting at all, but instead each instance of the string object has a 16-byte member array for short strings. This increases the string object size up to seven DWORDs (28 bytes)!

As my tests have demonstrated, the absence of reference counting severely hits performance when strings or objects containing strings are stored in STL's containers, and this is the most frequent scenario of string usage! On the other hand, using either a member array or a dynamically allocated buffer depending on the string length requires one conditional operation for each string reference. But this badly affects huge pipelines of modern processors, and overall performance of string operations proves to be lower than if the string buffer had to be always dynamically allocated (because allocation is done once, and references to strings are normally frequent). At last, when operating with large sets of string objects, the size of the object itself becomes important. For example, vector of 1.000.000 strings (far not the biggest one for a large search system) in VC++ 7.1 requires 28 Mb while it could be only 4 Mb in size.

To improve the performance, I have modified the basic_string class from VC++ 6.0 to amend the flaws mentioned above and to make it compatible with the VC++ 7.1 iterator model. Now, BasicString class can be based not only on the native STL's basic_string, but also on its modified version contained in the header "xstring.h". Unfortunately, the compiler bug in VC++ 6.0sp5 prevents usage of the modified version with Visual Studio 6. This compiler generates incorrect code because of a special inheritance graph allowing EBO. Therefore, usage of the optimized basic_string version is suppressed in VC++ 6.0.

In VC++ 7.1, the optimized version of basic_string is used by default. To force using native STL's implementation, define the USE_CURRENT_STL_IMPL flag before including the "BasicString.h" header.

The main improvements in the BasicString class provided by the optimized basic_string version are as follows:

  • The compact object layout—the only DWORD vs. four DWORs in VC++ 6, and seven DWORDs in VC++ 7.1 (!);

  • Optimized copy/assignment implementation;

  • Optimized GetBuffer/ReleaseBuffer performance;

  • Support for maximally quick initialization of temporary string objects with a string literal via the family of _R... macros. For more information, see the comments for these macros declaration in the "BasicString.h" header.

Other improvements (not depending on the basic_string class) are:

  • Template constructor that is used to construct a BasicString object from any type, which either can be converted to pointer to underlying string element type (const _E*), or to const char*, or to const wchar_t*, or has the c_str() method.

    This constructor prevents ambiguity when the source type can be implicitly converted to both const char* and const wchar_t* (and in this case selects the most efficient way of initializing).

    Actually, this allows you to create BasicString objects from any extant string class and, potentially, from future string classes without adding specialized constructors (e.g. the first version of BasicString contained specialized conversion constructors for _bstr_t and CString, now they became unnecessary).

    The only side-effect of using this constructor is bulky compiler error messages when you try to create a string from the object of improper type.

  • Extensible ToStr/ToWstr/ToAstr macros semantics. You can make any type convertible to the String/WString/AString type by means of a simple declaration using one of the DEFINE_TYPE_TO_STRING / DEFINE_TYPE_TO_STRING_x macros. Look how this is done for RECT, POINT, SIZE, CRect, CPoint, and CSize types at the end of the "BasicString.h" header.

Incompatibilities with the first version include:

  • Definition of the BasicString class has been moved from the std namespace to std_ex;

  • Constructor taking UINT of a string resource ID is not supported anymore. Instead, cast UINT to LPCSTR or LPCWSTR explicitly before passing it to the constructor.

  • The ToTstr, ResToTstr, and GuidToTstr macros have been renamed to ToStr, ResToStr, and GuidToStr correspondingly.

  • The set_bstr method has been renamed to realloc_bstr.

Note also that I have not tested usage of the BasicString objects based on the optimized version of the basic_string class with the iostream library.

New Methods Summary

The following table comprises the new methods added by the BasicString class to its STL's basic_string predecessor. Because almost all new methods have both MFC- and STL-like names, the table has three columns. The first two contain MFC- and STL-style names of new methods, and the third column—the names of extant basic_string methods, corresponding to the added CString equivalents.

New methods and macros Extant basic_string methods
BasicString ( HINSTANCE, UINT nStringResourceID, ... )
BasicString ( const GUID& )
operator const char* ()
operator const wchar_t* ()
operator _bstr_t ()
operator CString ()
operator CStringA ()
operator CStringW ()
ToStr
ToWstr
ToAstr
operator = ( const char* )
operator = ( const wchar_t* )
operator = ( const _bstr_t& )
operator = ( const CString& )
operator = ( const GUID& )
LoadString
SetResourceHandle
load
ResToTstr
ResToWstr
ResToAstr
GetBuffer
ReleaseBuffer
get_buf
set_buf
AllocSysString
SetSysString
bstr
realloc_bstr
Format
FormatV
printf
vprintf
GuidToStr
GuidToWstr
GuidToAstr
StrToGuid
GetGuid
FindGuid
guid
find_guid
Compare
compare
CompareCase
CompareNoCase
cmp_case
cmp_no_case
Find
ReverseFind
FindOneOf
FindOneNotOf
FindLastOf
FindLastNotOf
find
rfind
find_first_of
find_first_not_of
find_last_of
findlast_not_of
SpanIncluding
SpanExcluding
substr_of
substr_not_of
TrimLeft
TrimRight
trim
rtrim
FormatMessage
FormatMessageV
format_msg
vformat_msg
FormatSystemMessage
FormatSystemMessageV
FormatModuleMessage
FormatModuleMessageV
format_sys_msg
vformat_sys_msg
format_mod_msg
vformat_mod_msg
MakeUpper
MakeLower
to_upper
to_lower
Mid
Right
Left
substr
Insert
Delete
Replace
insert
erase
replace
GetLength
IsEmpty
length
empty

Platform Note

Despite the fact that the BasicString class is STL-based, it violates the STL's principle of platform independence by using some NT platform-specific methods. If your target OS is not Windows, define the _NO_WINDOWS symbol before the first inclusion of this header. This will exclude the code from using Windows-specific APIs.

Additionally, find calls to the functions WideCharToMultiByte and MultiByteToWideChar and replace them with the currently commented standard C-library function calls. But note that they do not use the current system locale (at least with VC++), so if you are writing multilingual applications, you must manage locales manually using proper C-library functions.

Downloads

Download source - 23 Kb

【信息科学与工程学】【数据科学】数据科学领域——第三篇 数学08 几何学00总篇 编号英文名称中文名称简要说明/归属1Foundations of Geometry几何基础公理化方法, Hilbert《几何基础》2Euclidean Geometry (Synthetic)欧几里得几何(综合法)《几何原本》传统3Analytic Geometry解析几何坐标方法, Descartes, Fermat4Plane Geometry平面几何三角形、圆、共点共线等经典问题5Solid Geometry立体几何三维空间中的图形与度量6Non-Euclidean Geometry非欧几何平行公设不 阅读详情

相关推荐

C++ 回调技术 用于 C++ 最小 Agentic Loop 实现

C++ 回调技术

"Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right

使用matlab 引发的错误; 原因是, 变量存储着之前的值而没有被清空, 因而现在被赋予的值与之前的值产生size不同冲突; 解决: clear variable;

xingtianyao的博客 4759

王堃阳.企业家演说私教值不值得请.pdf

王堃阳.企业家演说私教值不值得请

如何解决“无法执行赋值,因为‘cvx‘类型的值不可转换为‘double‘

【代码】如何解决“无法执行赋值,因为'cvx'类型的值不可转换为'double'

qq_29327495的博客 1015

沼气生产设施流体输送系统优化设计与经济性分析(Matlab代码实现)

内容概要:本文围绕沼气生产设施中的流体输送系统开展优化设计与经济性分析,重点利用Matlab编程实现对管道系统的流体动力学建模,并以总年化成本(TAC)最小化为目标进行系统优化。研究内容涵盖压力损失、流量分配、管径选型等关键参数的计算与优化,结合工程经济学方法综合评估不同设计方案的成本效益。通过构建精确的数学模型并采用高效的优化算法求解,实现了系统能效与经济性的协同提升,为沼气工程中流体输送环节的设计提供了科学依据与技术支持。; 适合人群:具备流体力学、能源工程或环境工程等相关专业背景,熟悉Matlab编程的科研人员及工程技术人员,特别适用于从事可再生能源系统设计与优化工作的研究生和一线工程师。; 使用场景及目标:①应用于沼气厂等生物质能源项目的管道系统设计与改造,优化流体输送效率;②为工程方案提供经济性评估工具,辅助决策最优管径与泵送配置,降低运营成本;③作为教学与科研案例,用于讲授流体系统建模与优化方法。; 阅读建议:建议读者结合Matlab代码深入理解模型构建与算法实现过程,重点关注目标函数设定、约束条件处理及优化结果的工程解读,并可通过调整参数进行仿真验证,以增强对系统设计规律的认知。

CGAL-5.6的安装与编译(Win10+vs2022+CGAL-5.6+Boost1.82.0)

CGAL是Computational Geometry Algorithms Library(计算几何算法库)的缩写,C++的高效算法库。CGAL只是一个头文件库(从5.0版本开始),这意味着CGAL无需编译,只需安装好CGAL的依赖项即可。CGAL5.6。

baidu_34931359的博客 3913

CVX error:Conversion to double from cvx is not possible解决方案

昨天在做MATLAB仿真的时候遇到了这个问题,真的是解决了好几个小时。 背景:用CVX工具箱做蒙特卡洛实验(就是多次重复实验) 报错:如题 百思不得其解。 解决过程 1.CVX USER'S GUIDE; 他说要把变量声明一下,写成expression variables的形式,于是我就把提示报错行的那块在cvx_begin后声明了一下,但是依然报错; 2.继续搜百度,在cv

冬瓜班小朋友的博客 3180

在MDK5.37版本中添加Complier Version 5( 解决Missing Compiler Version 5 )

本文章仅作为个人学习记录,方法也是从其他博主的博客中得到的,链接如下:二、Keil——Missing Compiler Version 5 和 core_cm3.c 问题解决 - YI颗白菜 - 博客园 (cnblogs.com) 问题描述 更新最新的keil版本(MDK5.37)后,在编译以前版本的工程文件时,发现出现了非常多的报错,在网上搜索之后发现原来时编译器版本不匹配的问题,即MDK5.37中使用的是Version 6版本的编译器,而缺少Version 5,对于以前编写的工

leveling99的博客 1万+

从 cvx 转换为 double 时出现以下错误:无法从 cvx 转换为 double。

初学cvx,今天在做一个仿真时,出现了“无法从 cvx 转换为 double。”这个错误,我是中文版的,英文版的应该表达为“Conversion to double from cvx is not possible.”类似的。 我原来的代码大概是这个的: z=zeros(1,K); cvx_begin sdp variable x; maximize t; subject to ...

Erican_tang的博客 1万+

OpenCv案例(七): 基于OpenCvSharp计算图像的清晰度(自动对焦)

自动对焦,其实是对相机成像的清晰值得计算,若对焦不清晰,成像的清晰度低,视觉效果模糊。若是在工业检测行业,对焦不准确,可能会造成严重后果;对焦准确的图像,其清晰度高,对比度鲜明,层次明显。

qq_37835727的博客 7128

焦距与视差的关系及其对深度估计的影响

焦距在立体视觉中的作用至关重要,它直接影响视差的大小,从而影响深度估计的精度。焦距越长,视差差异越大,物体的深度估计就越精确。这一关系使得焦距长的相机在一些需要高精度深度估计的应用场景中更加优越。了解焦距与视差的关系,对于优化相机配置和提升深度估计精度具有重要意义。在实践中,选择合适的焦距对于获得精确的深度信息至关重要,特别是在自动驾驶、虚拟现实、三维重建等领域,精确的深度估计能够提供更好的用户体验和技术支持。

计算机科学与技术专业学生的成长之路 1684

C++模板进阶:typename、函数模板与默认参数实战解析

C++模板是泛型编程的核心,它允许开发者编写与类型无关的通用代码,从而提升代码的复用性和性能。其工作原理基于编译期的类型推导和实例化,通过将类型作为参数,编译器能为不同数据类型生成特化的代码版本。这一机制的技术价值在于实现了类型安全的抽象,避免了运行时开销,是标准模板库(STL)的基石。在实际应用中,模板广泛用于容器、算法和元编程等场景。本文聚焦于C++模板编程中的几个关键进阶主题:typename关键字在嵌套依赖名称中的消歧义作用,函数模板的类型推导与特化策略,以及默认模板参数如何提升接口的友好度。通过剖

weixin_34185320的博客 329

《从零搭建Vue3项目实战》(AI辅助搭建Vue3+ElemntPlus后台管理项目)零基础入门系列第一篇:开发环境准备

vue3入门实战:环境准备篇

感谢阅读 1390

C++面试高频考点解析:从内存管理到多线程并发

在软件工程领域,内存管理与并发编程是构建高性能、可靠系统的核心技术基础。内存管理涉及资源的有效分配与释放,其核心原理在于通过指针、引用及智能指针等机制,实现对内存的精确控制,从而避免内存泄漏和非法访问。多线程并发则通过同步原语、原子操作等机制,确保数据一致性和程序正确性,其技术价值在于充分利用多核处理器性能,提升系统吞吐量。这些技术在游戏引擎、高频交易、嵌入式系统等对性能与可靠性要求极高的场景中尤为重要。本文聚焦C++面试中的高频问题,深入探讨智能指针的所有权语义、RAII设计模式、多线程数据竞争及内存模型

hideto 490

课堂练习及课后作业2.1:外部中断

本关任务:通过相关知识以及实验回答:版本 1 内核的第 6 次时钟中断发生时,断点和恢复点(指令地址)分别是多少?本关任务:修改版本 0 内核,使得每发生 100 次时钟中断,就在屏幕上输出一个字符‘t’和当时的进程号,如“t(0)”表示0号进程运行时发生了时钟中断。本关任务:通过实际操作回答在输出第一行 0/1 字符的过程中(如下图所示),共发生了几次时钟中断?本关任务:修改版本 1 内核源码,使得每次时钟中断发生时,都在屏幕上输出字符‘t’。分析版本1内核,找到第一次时钟中断的恢复点地址。

Junds0的博客 1万+

ardupilot 日志分析《xKF1信息》

ardupilot 日志分析系列将会把ardupilot所有的日志文档进行分析,为我们分析无人机的运行状态,炸鸡原因,传感器状态,电机状态,控制信息,滤波信息做准备。本节主要分析xKF1日志信息,欢迎批评指正。学习好ardupilot必须会分析飞行日志,从飞行日志中我们可以学到很多无人机的知识。无人机是综合知识的体现,涵盖:导航、控制、滤波、算法、协议等各种知识,只有更全面的学习,才能在无人机的道路上越走越远。

陌城烟雨 1237

C++进阶核心:从对象模型到并发编程的深度实践指南

C++作为一门支持多范式编程的系统级语言,其核心价值在于对内存和硬件的精细控制能力。理解其底层原理,如对象在内存中的布局、资源生命周期管理,是编写高效、健壮程序的基础。RAII(资源获取即初始化)原则和智能指针等技术,是实现自动化资源管理、避免内存泄漏的关键实践。随着多核处理器普及,并发编程成为提升性能的重要手段,掌握线程、互斥锁、条件变量及原子操作,能有效解决数据竞争和同步问题。这些底层机制与高级抽象的结合,使得C++在游戏引擎、高频交易、嵌入式系统等对性能有严苛要求的应用场景中不可替代。本文聚焦于对象模

weixin_30411819的博客 606

一篇文章带你认识 SpringBoot

文章目录一、原有 Spring 优缺点分析二、SpringBoot 的概述 一、原有 Spring 优缺点分析 (1)Spring 的优点分析 Spring是Java企业版(Java Enterprise Edition,JEE,也称J2EE)的轻量级代替品。无需开发重量级的Enterprise JavaBean(EJB),Spring为企业级Java开发提供了一种相对简单的方法,通过依赖注入和面向切面编程,用简单的 Java 对象(Plain Old Java Object,POJO)实现了EJB的功能。

南淮北安的博客 778

企业级文档在线预览解决方案:kkFileView技术架构与实施实践

在数字化转型浪潮中,企业面临着海量文档在线预览的技术挑战。传统方案存在格式兼容性差、部署复杂、维护成本高等问题,严重影响了团队协作效率。kkFileView作为基于Spring Boot的开源文件在线预览项目,提供了一套完整的文档预览解决方案,支持超过50种文件格式,包括CAD图纸、Office文档、PDF、3D模型等专业格式,为企业级应用提供了稳定可靠的文档预览服务。 ## 问题场景:企业文档

gitblog_00531的博客 938

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

构建企业级高性能文件在线预览系统的架构设计实践

在当今数字化办公环境中,企业面临着海量文件格式兼容性差、预览体验不一致、系统性能瓶颈等核心挑战。kkFileView作为基于Spring Boot的通用文件在线预览解决方案,通过创新的架构设计解决了这些技术难题,为企业提供了高性能、可扩展的文件预览服务。本文将从技术架构、核心模块设计、性能优化等维度,深度解析kkFileView如何构建一个支持30+文件格式、日处理百万级请求的企业级文件预览系统。

gitblog_00536的博客 415

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

C++模板本质:编译期元编程与零开销抽象原理

C++模板是实现泛型编程的核心机制,其本质并非运行时多态,而是编译期静态生成特化代码的元编程范式。它通过模板实例化、参数推导和约束(如concepts或SFINAE)在编译阶段完成类型适配与逻辑定制,确保零运行时开销。这一机制支撑了std::vector、std::sort等标准组件的高性能,也广泛应用于策略模式、内存池分配器及编译期计算等工程场景。理解模板如何将一份蓝图转化为多份专属实现,是掌握现代C++底层设计与高效系统开发的关键基础。

weixin_30825199的博客 389

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

C++11三大核心:类访问控制、可变参数模板与Lambda闭包

C++11标志着从‘带类的C’到现代系统编程的范式跃迁。其核心不仅在于语法更新,更在于类型系统、内存模型与并发原语的底层重构。类的public/protected/private本质是ABI契约而非运行时权限;可变参数模板中的'...'是编译期参数包解包指令,支撑完美转发与类型安全工厂;lambda表达式实为编译器生成的闭包类,捕获方式直接决定内存布局与生命周期安全。这些机制共同构成C++11工程落地的基石——在嵌入式通信、Qt多线程、高频交易等对稳定性与性能极度敏感的场景中,理解访问控制的内存布局影响、可

weixin_30336061的博客 1974

配置FindBugs和常见FindBugs错误

配置FindBugs: 在这里可以对FindBugs规则等进行详细设置。   选择你的项目,右键 => Properties => FindBugs => 1 Run Automatically开关 当此项选中后,FindBugs将会在你修改Java类时自动运行,如你设置了Eclipse自动编译开关后,当你修改完Java文件保存,FindBugs就会运行,并将相...

weixin_30354675的博客 1314

代码审查常见代码质量问题

配套的Bug解释模式 为了有针对性的使用这个工具,减少bug的误报,提高使用效率,我们选择了10个左右的bug模式,下面就是对这10个模式的解释。 这些bug可能会引起程序的性能或逻辑问题. 需要说明的是,findbugs能检测的bug pattern远不仅于此,甚至可以定制自己的探测器,因此,这个文档会不断扩充,同时,也欢迎大家不断探索和分享使用实践. 大的分类主要包括以

邢超的博客 2万+

Types方法之isCastable-isConvertible

5. Conversions and Promotions 5.1. Kinds of Conversion5.1.1. Identity Conversion5.1.2. Widening Primitive Conversion5.1.3. Narrowing Primitive Conversion5.1.4. Widening and Narrowing Primitiv...

209
上一篇: 微软内部文件:Longhorn相关工作外包印度
下一篇: Using ADO from C++
普通网友
博客等级 码龄22年 1万+粉丝 3156原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址