_CrtReportBlockType
傳回與指定偵錯堆積區塊指標相關聯的區塊類型/子類型。
語法
int _CrtReportBlockType(
const void * pBlock
};
參數
pBlock
有效偵錯堆積區塊的指標。
傳回值
當傳遞有效的偵錯堆積指標時,_CrtReportBlockType
函式會傳回 int
形式的區塊類型和子類型。 當傳遞無效的指標時,函式會傳回 -1。
備註
若要擷取 所 _CrtReportBlockType
傳回的類型和子類型,請在傳回值上使用宏 _BLOCK_TYPE
和 _BLOCK_SUBTYPE
(兩者都定義于 Crtdbg.h 中)。
如需配置區塊類型及其使用方式的相關資訊,請參閱 偵錯堆積 上的區塊類型。
需求
常式 | 必要的標頭 |
---|---|
_CrtReportBlockType |
<crtdbg.h> |
如需相容性詳細資訊,請參閱相容性。
程式庫
僅限偵錯版本的 C 執行階段程式庫。
範例
// 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);
}
範例輸出
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.
另請參閱
_CrtDoForAllClientObjects
_CrtSetDumpClient
_CrtMemDumpAllObjectsSince
_CrtDumpMemoryLeaks
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應