Skip to content

Latest commit

 

History

History
100 lines (78 loc) · 2.75 KB

File metadata and controls

100 lines (78 loc) · 2.75 KB
description title ms.date api_name api_location api_type topic_type f1_keywords helpviewer_keywords ms.assetid
Learn more about: _heapchk
_heapchk
4/2/2020
_heapchk
_o__heapchk
msvcrt.dll
msvcr80.dll
msvcr90.dll
msvcr100.dll
msvcr100_clr0400.dll
msvcr110.dll
msvcr110_clr0400.dll
msvcr120.dll
msvcr120_clr0400.dll
ucrtbase.dll
api-ms-win-crt-heap-l1-1-0.dll
DLLExport
apiref
_heapchk
heapchk
debugging [CRT], heap-related problems
consistency checking of heaps
heapchk function
heaps, checking consistency
_heapchk function
859619a5-1e35-4f02-9e09-11d9fa266ec0

_heapchk

Runs consistency checks on the heap.

Syntax

int _heapchk( void );

Return value

_heapchk returns one of the following integer manifest constants defined in Malloc.h.

Return value Condition
_HEAPBADBEGIN Initial header information is bad or can't be found.
_HEAPBADNODE Bad node has been found or heap is damaged.
_HEAPBADPTR Pointer into heap isn't valid.
_HEAPEMPTY Heap hasn't been initialized.
_HEAPOK Heap appears to be consistent.

In addition, if an error occurs, _heapchk sets errno to ENOSYS.

Remarks

The _heapchk function helps debug heap-related problems by checking for minimal consistency of the heap. If the operating system doesn't support _heapchk(for example, Windows 98), the function returns _HEAPOK and sets errno to ENOSYS.

By default, this function's global state is scoped to the application. To change this behavior, see Global state in the CRT.

Requirements

Routine Required header Optional header
_heapchk <malloc.h> <errno.h>

For more compatibility information, see Compatibility.

Example

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

See also

Memory allocation
_heapadd
_heapmin
_heapset
_heapwalk