_CrtIsValidHeapPointer

確認指定的指標是在本機的堆積 (偵錯版本)。

int _CrtIsValidHeapPointer( 
   const void *userData 
);

參數

  • userData
    指標配置的記憶體區塊的開頭。

傳回值

_CrtIsValidHeapPointer指定的指標是否位於本機的堆積,則傳回 TRUE。否則,函數會傳回 FALSE。

備註

_CrtIsValidHeapPointer函式用來確保特定記憶體位址是在本機的堆積中。本機的堆積指的是 c 執行階段程式庫的特定執行個體所建立和管理的堆積。如果動態連結程式庫 (DLL) 中包含執行階段程式庫的靜態連結,它就會有自己的執行階段堆積中,因此它自己的堆積,獨立於應用程式的本機的堆積執行個體。當 _DEBUG 尚未定義,會呼叫**_CrtIsValidHeapPointer**在前置處理過程中移除。

這個函數會傳回 TRUE 或 FALSE,因為它可以傳遞給其中一個 _ASSERT 巨集] 以建立簡單的偵錯錯誤處理機制。如果指定的位址不是位於本機的堆積,以下範例會產生判斷提示失敗:

_ASSERTE( _CrtIsValidHeapPointer( userData ) );

如需有關如何**_CrtIsValidHeapPointer**可以搭配其他的偵錯函式和巨集,請參閱來進行驗證和報告使用的巨集。如需有關如何記憶體區塊會配置、 初始化,而且在基底堆積的偵錯版本管理的資訊,請參閱記憶體管理和偵錯堆積

需求

常式

所需的標頭

_CrtIsValidHeapPointer

<crtdbg.h>

如需相容性資訊,請參閱相容性在簡介中。

文件庫

偵錯版本的 C 執行階段程式庫只。

範例

// crt_isvalid.c
/*
 * This program allocates a block of memory using _malloc_dbg
 * and then tests the validity of this memory by calling 
 * _CrtIsMemoryBlock,_CrtIsValidPointer, and _CrtIsValidHeapPointer.
 */

#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <crtdbg.h>

#define  TRUE   1
#define  FALSE  0

int main( void )
{
        char *my_pointer;

        /* 
         * Call _malloc_dbg to include the filename and line number
         * of our allocation request in the header information
         */
        my_pointer = (char *)_malloc_dbg( sizeof(char) * 10, 
        _NORMAL_BLOCK, __FILE__, __LINE__ );

        // Ensure that the memory got allocated correctly
        _CrtIsMemoryBlock((const void *)my_pointer, sizeof(char) * 10, 
        NULL, NULL, NULL );

         // Test for read/write accessibility
        if (_CrtIsValidPointer((const void *)my_pointer, 
        sizeof(char) * 10, TRUE))
                printf("my_pointer has read and write accessibility.\n");
        else
                printf("my_pointer only has read access.\n");

        // Make sure my_pointer is within the local heap
        if (_CrtIsValidHeapPointer((const void *)my_pointer))
                printf("my_pointer is within the local heap.\n");
        else
                printf("my_pointer is not located within the local"
                       " heap.\n");

        free(my_pointer);
}

Output

my_pointer has read and write accessibility.
my_pointer is within the local heap.

.NET Framework 對等用法

不適用。 若要呼叫標準的 c 函式,使用PInvoke。 如需詳細資訊,請參閱平台叫用範例

請參閱

參考

偵錯常式