Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Gibt den Blocktyp/den Untertyp zurück, der einem angegebenen Debugheapblockzeiger zugeordnet ist.
Syntax
int _CrtReportBlockType(
const void * pBlock
);
Parameter
pBlock
Zeiger für einen gültigen Debugheapblock.
Rückgabewert
Wenn ein gültiger Debugheapzeiger übergeben wird, gibt die _CrtReportBlockType
-Funktion den Blocktyp und den Untertyp in Form von int
zurück. Wenn ein ungültiger Zeiger übergeben wird, gibt die Funktion -1 zurück.
Hinweise
Verwenden Sie zum Extrahieren des Typs und untertyps, der von _CrtReportBlockType
diesem zurückgegeben wird, die Makros _BLOCK_TYPE
und _BLOCK_SUBTYPE
(beide in Crtdbg.h definiert) für den Rückgabewert.
Informationen zu den Zuordnungsblocktypen und deren Verwendung finden Sie unter "Typen von Blöcken" im Debug-Heap.
Anforderungen
Routine | Erforderlicher Header |
---|---|
_CrtReportBlockType |
<crtdbg.h> |
Weitere Informationen zur Kompatibilität finden Sie unter Kompatibilität.
Libraries
Nur Debugversionen von C-Laufzeitbibliotheken
Beispiel
// crt_crtreportblocktype.cpp
// compile with: /MDd
#include <malloc.h>
#include <stdio.h>
#include <crtdbg.h>
void __cdecl Dumper(void *ptr, void *)
{
int block = _CrtReportBlockType(ptr);
_RPT3(_CRT_WARN, "Dumper found block at %p: type %d, subtype %d\n", ptr,
_BLOCK_TYPE(block), _BLOCK_SUBTYPE(block));
}
void __cdecl LeakDumper(void *ptr, size_t sz)
{
int block = _CrtReportBlockType(ptr);
_RPT4(_CRT_WARN, "LeakDumper found block at %p:"
" type %d, subtype %d, size %d\n", ptr,
_BLOCK_TYPE(block), _BLOCK_SUBTYPE(block), sz);
}
int main(void)
{
_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) |
_CRTDBG_LEAK_CHECK_DF);
_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
_malloc_dbg(10, _NORMAL_BLOCK , __FILE__, __LINE__);
_malloc_dbg(10, _CLIENT_BLOCK | (1 << 16), __FILE__, __LINE__);
_malloc_dbg(20, _CLIENT_BLOCK | (2 << 16), __FILE__, __LINE__);
_malloc_dbg(30, _CLIENT_BLOCK | (3 << 16), __FILE__, __LINE__);
_CrtDoForAllClientObjects(Dumper, NULL);
_CrtSetDumpClient(LeakDumper);
}
Beispielausgabe
Dumper found block at 00314F78: type 4, subtype 3
Dumper found block at 00314F38: type 4, subtype 2
Dumper found block at 00314F00: type 4, subtype 1
Detected memory leaks!
Dumping objects ->
crt_crtreportblocktype.cpp(30) : {55} client block at 0x00314F78, subtype 3, 30 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
crt_crtreportblocktype.cpp(29) : {54} client block at 0x00314F38, subtype 2, 20 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
crt_crtreportblocktype.cpp(28) : {53} client block at 0x00314F00, subtype 1, 10 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD
crt_crtreportblocktype.cpp(27) : {52} normal block at 0x00314EC8, 10 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD
Object dump complete.
Siehe auch
_CrtDoForAllClientObjects
_CrtSetDumpClient
_CrtMemDumpAllObjectsSince
_CrtDumpMemoryLeaks