_CrtSetDebugFillThreshold
div
eof
TOC
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

_CrtSetDebugFillThreshold 

Retrieves or modifies the threshold controlling buffer-filling behavior in debug functions.


size_t _CrtSetDebugFillThreshold(
   size_t _NewThreshold
);

Parameters

newThreshold

New threshold.

The previous threshold.

The debug versions of some security-enhanced CRT functions fill the buffer passed to them with a special character (0xFD). This helps to find cases where the incorrect size was passed to the function. Unfortunately, it also reduces performance. To improve performance, use _CrtSetDebugFillThreshold to disable buffer-filling for buffers larger than the threshold. A threshold of 0 will disable it for all buffers.

The default threshold is SIZE_T_MAX.

Here is a list of the affected functions.

Routine Required header Compatibility

_CrtSetDebugFillThreshold

<crtdbg.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows Millennium Edition, 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.

Libraries

Debug versions of C run-time libraries only.

// crt_crtsetdebugfillthreshold.cpp
// compile with: /MTd
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <crtdbg.h>

void Clear( char buff[], size_t size )
{
   for( int i=0; i<size; ++i )
      buff[i] = 0;
}

void Print( char buff[], size_t size )
{
   for( int i=0; i<size; ++i )
      printf( "%02x  %c\n", (unsigned char)buff[i], buff[i] );
}

int main( void )
{
   char buff[10];

   printf( "With buffer-filling on:\n" );
   strcpy_s( buff, _countof(buff), "howdy" );
   Print( buff, _countof(buff) );

   _CrtSetDebugFillThreshold( 0 );

   printf( "With buffer-filling off:\n" );
   Clear( buff, _countof(buff) );
   strcpy_s( buff, _countof(buff), "howdy" );
   Print( buff, _countof(buff) );
}
With buffer-filling on:
68  h
6f  o
77  w
64  d
79  y
00
fd  ²
fd  ²
fd  ²
fd  ²
With buffer-filling off:
68  h
6f  o
77  w
64  d
79  y
00
00
00
00
00

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

Show:
© 2016 Microsoft