Export (0) Print
Expand All
div
eof
Expand Minimize
This topic has not yet been rated - Rate this topic

_heapset 

Checks heaps for minimal consistency and sets the free entries to a specified value.


int _heapset( 
   unsigned int fill 
);

Parameters

fill

Fill character.

_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.

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

The _heapset function shows free memory locations or nodes that have been unintentionally overwritten.

_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. If the operating system does not support _heapset (for example, Windows 98), the function returns _HEAPOK and sets errno to ENOSYS.

Routine Required header Optional header Compatibility

_heapset

<malloc.h>

<errno.h>

Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

For more compatibility information, see Compatibility in the Introduction.

// 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 );
}

Output

OK - heap is fine

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.