共用方式為


_tempnam_dbg, _wtempnam_dbg

Function versions of _tempnam, _wtempnam, tmpnam, _wtmpnam that use the debug version of malloc, _malloc_dbg.

char *_tempnam_dbg(
   const char *dir,
   const char *prefix,
   int blockType,
   const char *filename,
   int linenumber 
);
wchar_t *_wtempnam_dbg(
   const wchar_t *dir,
   const wchar_t *prefix,
   int blockType,
   const char *filename,
   int linenumber 
);

Parameters

  • dir
    The path used in the file name if there is no TMP environment variable, or if TMP is not a valid directory.

  • prefix
    The string that will be pre-pended to names returned by _tempnam.

  • blockType
    Requested type of memory block: _CLIENT_BLOCKor _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 function returns a pointer to the name generated or NULL if there is a failure. Failure can occur if there is an invalid directory name specified in the TMP environment variable and in the dir parameter.

Note

free (or free_dbg) does need to be called for pointers allocated by _tempnam_dbg and _wtempnam_dbg.

Remarks

The _tempnam_dbgand _wtempnam_dbgfunctions are identical to _tempnamand _wtempnamexcept that, when _DEBUGis defined, these functions use the debug version of malloc and _malloc_dbg, to allocate memory if NULL is passed as the first parameter. For more information, 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 _tempnam and _wtempnam are remapped to _tempnam_dbg and _wtempnam_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, see Types of Blocks on the Debug Heap.

Generic-Text Routine Mappings

TCHAR.H routine

_UNICODE & _MBCS not defined

_MBCS defined

_UNICODE defined

_ttempnam_dbg

_tempnam_dbg

_tempnam_dbg

_wtempnam_dbg

Requirements

Routine

Required header

_tempnam_dbg, _wtempnam_dbg

<crtdbg.h>

For additional compatibility information, see Compatibility in the Introduction.

.NET Framework Equivalent

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

See Also

Reference

_tempnam, _wtempnam, tmpnam, _wtmpnam

Stream I/O

Concepts

Debug Versions of Heap Allocation Functions