_CrtIsValidHeapPointer

지정된 포인터가 일부 C 런타임 라이브러리에서 할당된 힙에 있는지 확인하지만 호출자의 CRT 라이브러리에서 할당된 힙에 있는지는 확인하지 않을 수 있습니다. Visual Studio 2010 이전의 CRT 버전에서 이 함수는 지정된 포인터가 로컬 힙에 있는지 확인합니다(디버그 버전에만 해당).

구문

int _CrtIsValidHeapPointer(
   const void *userData
);

매개 변수

userData
할당된 메모리 블록의 시작 부분에 대한 포인터입니다.

반환 값

_CrtIsValidHeapPointer 는 지정된 포인터가 모든 CRT 라이브러리 인스턴스에서 공유하는 힙에 있으면 반환 TRUE 됩니다. Visual Studio 2010 이전의 CRT 버전에서 이 함수는 지정된 포인터가 로컬 힙에 있으면 반환 TRUE 합니다. 그렇지 않으면 FALSE를 반환합니다.

설명

이 함수를 사용하지 않는 것이 좋습니다. Visual Studio 2010 CRT 라이브러리부터 모든 CRT 라이브러리에서는 하나의 OS 힙인 프로세스 힙을 공유합니다. _CrtIsValidHeapPointer 함수는 포인터가 CRT 힙에서 할당되었는지를 보고하지만 호출자의 CRT 라이브러리에서 할당되었는지는 보고하지 않습니다. 예를 들어 CRT 라이브러리의 Visual Studio 2010 버전을 사용하여 할당된 블록을 살펴보겠습니다. _CrtIsValidHeapPointer VISUAL Studio 2012 버전의 CRT 라이브러리에서 내보낸 함수가 포인터를 테스트하면 반환됩니다TRUE. 이 테스트는 더 이상 유용하지 않습니다. Visual Studio 2010 이전 CRT 라이브러리 버전에서 이 함수는 특정 메모리 주소가 로컬 힙 내에 있는지 확인하는 데 사용됩니다. 로컬 힙은 C 런타임 라이브러리의 특정 인스턴스에서 만들어지고 관리되는 힙을 나타냅니다. DLL(동적 연결 라이브러리)에는 런타임 라이브러리에 대한 정적 링크가 들어 있으면 애플리케이션의 로컬 힙과 관계없이 런타임 힙의 고유한 인스턴스가 포함되고 이에 따라 고유한 힙이 포함됩니다. 정의되지 않은 경우 _DEBUG 전처리 중에 호출 _CrtIsValidHeapPointer 이 제거됩니다.

이 함수는 반환 TRUE 되거나 FALSE매크로 중 _ASSERT 하나에 전달되어 기본 디버깅 오류 처리 메커니즘을 만들 수 있습니다. 다음 예제에서는 지정된 주소가 로컬 힙 내에 없으면 어설션 오류가 발생합니다.

_ASSERTE( _CrtIsValidHeapPointer( userData ) );

다른 디버그 함수 및 매크로와 함께 사용할 수 있는 방법에 _CrtIsValidHeapPointer 대한 자세한 내용은 보고용 매크로를 참조하세요. 기본 힙의 디버그 버전에서 메모리 블록을 할당, 초기화 및 관리하는 방법에 대한 자세한 내용은 CRT 디버그 힙 세부 정보를 참조 하세요.

요구 사항

루틴에서 반환된 값 필수 헤더
_CrtIsValidHeapPointer <crtdbg.h>

호환성에 대한 자세한 내용은 호환성을 참조하세요.

라이브러리

C 런타임 라이브러리의 디버그 버전만 해당됩니다.

예시

다음 예제에서는 Visual Studio 2010 이전의 C 런타임 라이브러리에서 메모리를 사용할 때 메모리가 유효한지 여부를 테스트하는 방법을 보여 줍니다. 이 예제는 레거시 CRT 라이브러리 코드 사용자를 위해 제공됩니다.

// 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);
}
my_pointer has read and write accessibility.
my_pointer is within the local heap.

참고 항목

디버그 루틴