_heapset

檢查堆積是否達到基本的一致性,並將可用的項目設定為指定的值。

重要

此函式已過時。 自 Visual Studio 2015 起,此函式即無法在 CRT 中使用。

語法

int _heapset(
   unsigned int fill
);

參數

fill
填滿字元。

傳回值

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

Description
_HEAPBADBEGIN 找不到初始標頭資訊或其無效。
_HEAPBADNODE 堆積已損毀或找到故障的節點。
_HEAPEMPTY 堆積未初始化。
_HEAPOK 堆積看似一致。

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

備註

_heapset 函式會顯示可用的記憶體位置,或不慎被覆寫的節點。

_heapset 會檢查堆積是否達到基本的一致性,然後將堆積中可用項目的每個位元組設為 fill 值。 這項已知值會顯示堆積中的哪些記憶體位置包含可用的節點,以及所含資料中有哪些不慎被誤寫而釋放出記憶體。 如果作業系統不支援 _heapset (例如 Windows 98),函式會傳 _HEAPOK 回 並將 設定 errnoENOSYS

需求

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

如需詳細的相容性資訊,請參閱簡介中的 Compatibility

範例

// crt_heapset.c
// This program checks the heap and
// fills in free entries with the character 'Z'.

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

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

   if( (buffer = malloc( 1 )) == NULL ) // Make sure heap is
      exit( 0 );                        //    initialized
   heapstatus = _heapset( 'Z' );        // Fill in free entries
   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;
   }
   free( buffer );
}
OK - heap is fine

另請參閱

記憶體配置
_heapadd
_heapchk
_heapmin
_heapwalk