_heapset_heapset

检查堆是否符合最小一致性,并将可用项设置为指定值。Checks heaps for minimal consistency and sets the free entries to a specified value.

重要

此函数已过时。This function is obsolete. 从 Visual Studio 2015 开始,CRT 中不再提供此函数。Beginning in Visual Studio 2015, it is not available in the CRT.

语法Syntax

int _heapset(   
   unsigned int fill   
);  

参数Parameters

fill
填充字符。Fill character.

返回值Return Value

_heapset 返回 Malloc.h 中定义的以下整数清单常量之一。_heapset returns one of the following integer manifest constants defined in Malloc.h.

_HEAPBADBEGIN
初始标头信息无效或未找到。Initial header information invalid or not found.

_HEAPBADNODE
堆已损坏或找到错误节点。Heap damaged or bad node found.

_HEAPEMPTY
堆未初始化。Heap not initialized.

_HEAPOK
堆看起来一致。Heap appears to be consistent.

此外,如果出现错误,_heapset 会将 errno 设置为 ENOSYSIn addition, if an error occurs, _heapset sets errno to ENOSYS.

备注Remarks

_heapset 函数表示可用内存位置或已经被无意覆盖的节点。The _heapset function shows free memory locations or nodes that have been unintentionally overwritten.

_heapset 检查堆上的最小一致性,然后将堆的可用项的每个字节设置为 fill 值。_heapset checks for minimal consistency on the heap and then sets each byte of the heap's free entries to the fill value. 此已知值表示堆的哪些内存位置包含可用节点,以及哪些位置包含为了释放内存而无意写入的数据。This known value shows which memory locations of the heap contain free nodes and which contain data that were unintentionally written to freed memory. 如果操作系统不支持 _heapset(例如 Windows 98),此函数则返回 _HEAPOK,并将 errno 设置为 ENOSYSIf the operating system does not support _heapset(for example, Windows 98), the function returns _HEAPOK and sets errno to ENOSYS.

惠?Requirements

例程所返回的值Routine 必需的标头Required header 可选标头Optional header
_heapset <malloc.h><malloc.h> <errno.h><errno.h>

有关更多兼容性信息,请参见“简介”中的 兼容性For more compatibility information, see Compatibility in the Introduction.

示例Example

// 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  

请参阅See Also

内存分配 Memory Allocation
_heapadd _heapadd
_heapchk _heapchk
_heapmin _heapmin
_heapwalk_heapwalk