Udostępnij za pośrednictwem


_strdup_dbg, _wcsdup_dbg

Versions of _strdup and _wcsdup that use the debug version of malloc.

char *_strdup_dbg(
   const char *strSource,
   int blockType,
   const char *filename,
   int linenumber 
);
wchar_t *_wcsdup_dbg(
   const wchar_t *strSource,
   int blockType,
   const char *filename,
   int linenumber 
);

Parameters

  • strSource
    Null-terminated source string.

  • blockType
    Requested type of memory block: _CLIENT_BLOCK or _NORMAL_BLOCK.

  • filename
    Pointer to name of source file that requested allocation operation or NULL.

  • linenumber
    Line number in source file where allocation operation was requested or NULL.

Return Value

Each of these functions returns a pointer to the storage location for the copied string or NULL if storage cannot be allocated.

Remarks

The _strdup_dbg and _wcsdup_dbg functions are identical to _strdup and _wcsdup except that, when _DEBUG is defined, these functions use the debug version of malloc, _malloc_dbg, to allocate memory for the duplicated string. For information on the debugging features of _malloc_dbg, see _malloc_dbg.

You do not need to call these functions explicitly in most cases. Instead, you can define the flag _CRTDBG_MAP_ALLOC. When _CRTDBG_MAP_ALLOC is defined, calls to _strdup and _wcsdup are remapped to _strdup_dbg and _wcsdup_dbg, respectively, with the blockType set to _NORMAL_BLOCK. Thus, you do not need to call these functions explicitly unless you want to mark the heap blocks as _CLIENT_BLOCK. For more information on block types, see Types of Blocks on the Debug Heap.

Generic-Text Routine Mappings

TCHAR.H routine

_UNICODE & _MBCS not defined

_MBCS defined

_UNICODE defined

_tcsdup_dbg

_strdup_dbg

_mbsdup

_wcsdup_dbg

Requirements

Routine

Required header

_strdup_dbg, _wcsdup_dbg

<crtdbg.h>

For additional compatibility information, see Compatibility in the Introduction.

Libraries

All debug versions of the C run-time libraries.

.NET Framework Equivalent

System::String::Clone

See Also

Reference

String Manipulation (CRT)

_strdup, _wcsdup, _mbsdup

Concepts

Debug Versions of Heap Allocation Functions