_heapchk

在堆積上執行一致性檢查。

語法

int _heapchk( void );

傳回值

_heapchk 會傳回下列在 Malloc.h 中定義的整數資訊清單常數之一。

傳回值 Condition
_HEAPBADBEGIN 初始標頭資訊不正確或找不到。
_HEAPBADNODE 找到不正確的節點或堆積損壞。
_HEAPBADPTR 堆積的指標無效。
_HEAPEMPTY 堆積尚未初始化。
_HEAPOK 堆積看似一致。

此外若是發生錯誤, _heapchk 會將 errno 設為 ENOSYS

備註

_heapchk 函式可透過檢查堆積的最小一致性來協助堆積相關問題的偵錯。 如果作業系統不支援 _heapchk (例如 Windows 98),函式會傳 _HEAPOK 回 並將 設定 errnoENOSYS

根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。

需求

常式 必要的標頭 選擇性標頭
_heapchk <malloc.h> <errno.h>

如需相容性詳細資訊,請參閱相容性

範例

// crt_heapchk.c
// This program checks the heap for
// consistency and prints an appropriate message.

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

int main( void )
{
   int  heapstatus;
   char *buffer;

   // Allocate and deallocate some memory
   if( (buffer = (char *)malloc( 100 )) != NULL )
      free( buffer );

   // Check heap status
   heapstatus = _heapchk();
   switch( heapstatus )
   {
   case _HEAPOK:
      printf(" OK - heap is fine\n" );
      break;
   case _HEAPEMPTY:
      printf(" OK - heap is empty\n" );
      break;
   case _HEAPBADBEGIN:
      printf( "ERROR - bad start of heap\n" );
      break;
   case _HEAPBADNODE:
      printf( "ERROR - bad node in heap\n" );
      break;
   }
}
OK - heap is fine

另請參閱

記憶體配置
_heapadd
_heapmin
_heapset
_heapwalk