_expand_dbg

调整指定的块在堆中的内存通过展开或收缩块 (请只调试版本)。

void *_expand_dbg( 
   void *userData,
   size_t newSize,
   int blockType,
   const char *filename,
   int linenumber 
);

参数

  • userData
    对以前指定的指针内存块。

  • newSize
    块的请求的新大小 (以字节为单位)。

  • blockType
    调整大小的请求的类型块: _CLIENT_BLOCK或 _NORMAL_BLOCK。

  • filename
    对请求源文件的名称的指针展开操作或 NULL。

  • linenumber
    在展开请求的操作或 NULL的源文件中的行号。

filename 和 linenumber 参数才可用,当 _expand_dbg 显式调用或 _CRTDBG_MAP_ALLOC 预处理器来定义。

返回值

在成功完成, _expand_dbg 返回指向已调整大小的内存块。由于内存不会移动,该地址是否与 userData。如果出现错误或块中不能展开到请求的范围,则返回 NULL。如果失败, errno 与从操作系统的信息有关该失败的性质。有关 errno的更多信息,请参见errno、_doserrno、_sys_errlist和_sys_nerr

备注

_expand_dbg功能是 _展开 函数的 " debug " 版本。当 _DEBUG 未定义时,每个调用 _expand_dbg减少到 _expand的调用。_expand和 _expand_dbg在基堆调整内存块,但是, _expand_dbg 满足一些调试功能:在测试块的两侧用户部分的缓冲区对于泄漏、跟踪一个块类型的参数特定分配类型和 filename/linenumber 信息确定分配请求的原点。

_expand_dbg 与请求的 newSize调整指定的内存块。稍有更多的空间。newSize 可能大于或小于最初分配的内存块范围。调试堆管理器用于附加空间链接调试内存块,并提供应用程序提供调试标题信息并复盖缓冲区。调整通过或扩展完成或缩短原始内存块。_expand_dbg 不移动内存块,如 _realloc_dbg 功能。

当 newSize 比原始的大小高版本时,内存块展开。在展开期间,因此,如果内存块未能扩展以容纳请求的大小, NULL 返回。当 newSize 比原始的大小小于时,内存块进行收缩,直到新范围中获取的。

有关如何的信息存储在基堆的调试版本中分配,初始化,并管理,请参见 内存管理和调试堆。有关分配的信息块类型以及如何使用它们,请参见 调试堆上的块类型。有关调用标准堆函数之间的差异的信息及其调试在应用程序的调试版本的版本,请参见 使用调试版本与基版本

此功能验证其参数。如果 memblock 是 null 指针,或者,如果大小大于 _HEAP_MAXREQ大,此函数调用无效参数处理程序,如 参数验证所述。如果执行允许继续, errno 设置为 EINVAL ,函数返回 NULL。

要求

实例

必需的头

_expand_dbg

crtdbg.h

有关更多兼容性信息,请参见中介绍的 兼容性

只调试 C 运行库 的版本。

示例

// crt_expand_dbg.c
//
// This program allocates a block of memory using _malloc_dbg
// and then calls _msize_dbg to display the size of that block.
// Next, it uses _expand_dbg to expand the amount of
// memory used by the buffer and then calls _msize_dbg again to
// display the new amount of memory allocated to the buffer.
//

#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <crtdbg.h>

int main( void )
{
   long *buffer;
   size_t size;

   // Call _malloc_dbg to include the filename and line number
   // of our allocation request in the header
   buffer = (long *)_malloc_dbg( 40 * sizeof(long),
                                 _NORMAL_BLOCK, __FILE__, __LINE__ );
   if( buffer == NULL )
      exit( 1 );

   // Get the size of the buffer by calling _msize_dbg
   size = _msize_dbg( buffer, _NORMAL_BLOCK );
   printf( "Size of block after _malloc_dbg of 40 longs: %u\n", size );

   // Expand the buffer using _expand_dbg and show the new size
   buffer = (long *)_expand_dbg( buffer, size + sizeof(long),
                                 _NORMAL_BLOCK, __FILE__, __LINE__ );

   if( buffer == NULL )
      exit( 1 );
   size = _msize_dbg( buffer, _NORMAL_BLOCK );
   printf( "Size of block after _expand_dbg of 1 more long: %u\n",
           size );

   free( buffer );
   exit( 0 );
}
  

注释

此程序的输出取决于计算机的能力展开所有部分。如果所有部分,将展开输出在输出部分反映。

.NET Framework 等效项

不适用。若要调用标准 C 函数,请使用 PInvoke。有关更多信息,请参见 平台调用示例

请参见

参考

调试实例

_malloc_dbg