RAD Studio
ContentsIndex
PreviousUpNext
heapfillfree

Header File 

alloc.h 

Category 

Memory Routines 

Prototype 

int heapfillfree(unsigned int fillvalue); 

Description 

Fills the free blocks on the heap with a constant value. 

Return Value 

One of the following values:

_HEAPCORRUPT 
Heap has been corrupted 
_HEAPEMPTY 
No heap 
_HEAPOK 
Heap is accurate 

Example

#include <stdio.h>
#include <alloc.h>
#include <mem.h>
#define NUM_PTRS  10
#define NUM_BYTES 16
int main(void)
{
   char *array[ NUM_PTRS ];
   int i;
   int res;
   for( i = 0; i < NUM_PTRS; i++ )
      array[ i ] = (char *) malloc( NUM_BYTES );
   for( i = 0; i < NUM_PTRS; i += 2 )
      free( array[ i ] );
   if( heapfillfree( 1 ) < 0 )
   {
      printf( "Heap corrupted.\n" );
      return 1;
   }
   for( i = 1; i < NUM_PTRS; i += 2 )
      memset( array[ i ], 0, NUM_BYTES );
   res = heapcheckfree( 1 );
   if( res < 0 )
      switch( res )
      {
         case _HEAPCORRUPT:
              printf( "Heap corrupted.\n" );
              return 1;
         case _BADVALUE:
              printf( "Bad value in free space.\n" );
              return 1;
         default:
              printf( "Unknown error.\n" );
              return 1;
      }
   printf( "Test successful.\n" );
   return 0;
}

Portability

POSIX 
Win32 
ANSI C 
ANSI C++ 
 
 
 
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!