_CrtIsValidHeapPointer
지정된 포인터가 로컬 힙에 있는지 확인합니다.(디버그 버전에만 해당)
int _CrtIsValidHeapPointer(
const void *userData
);
매개 변수
- userData
할당 된 메모리 블록의 시작 부분에 대한 포인터입니다.
반환 값
_CrtIsValidHeapPointer은 로컬 힙에 지정된 된 포인터일 경우 TRUE를 반환합니다. 그렇지 않은 경우 FALSE를 반환합니다.
설명
_CrtIsValidHeapPointer 함수를 사용하여 로컬 힙 내에서 특정 메모리 주소인지 확인합니다. 로컬 힙 힙에서 C 런타임 라이브러리의 특정 인스턴스의 생성과 관리를 나타냅니다. 동적 연결 라이브러리 (DLL)가 런타임 라이브러리에 연결된 정적 링크를 포함할 경우 , 런타임 힙 고유한 인스턴스를 가지고, 따라서 응용 프로그램 로컬 힙의 독립적인 고유한 힙을 가집니다. _DEBUG가 정의되어 있지 않으면 _CrtIsValidHeapPointer 에 대한 호출은 전처리 동안 제거됩니다.
이 함수에서 TRUE 또는 FALSE를 반환 하기 때문에, _ASSERT매크로 중 하나에 전달 되어 간단한 디버깅 오류 처리 메커니즘을 만들 수 있습니다. 다음 예제에서는 지정한 주소가 로컬 힙에 없을 때, 어설션 오류가 발생하는 것을 보여줍니다:
_ASSERTE( _CrtIsValidHeapPointer( userData ) );
_CrtIsValidHeapPointer 가 어떻게 기타 디버그 함수 및 매크로 함께 사용할 수 있는지에 대한 자세한 내용은보고서 매크로를 참조 하십시오. 기본 힙의 디버그 버전에서 메모리 블록이 어떻게 할당되고 초기화되고 관리되는지에 대한 자세한 내용은 CRT 디버그 힙 정보 를 참조하십시오.
요구 사항
루틴 |
필수 헤더 |
---|---|
_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를 사용합니다. 자세한 내용은 플랫폼 호출 예제를 참조하십시오.