我用new分配了一块内存,并且也存放了数据。
是否存在这样的函数,将这块内存区扩大,并且不改变原来的数据?
我查过,turbo c 中好像有setblock,但是在vc中找不到!
是否存在这样的函数,将这块内存区扩大,并且不改变原来的数据?
我查过,turbo c 中好像有setblock,但是在vc中找不到!
解决方案 »
- winsock send 和 recv 的问题
- sdi工程里关闭模式对话框时整个程序退出,为什么呀?
- 求教一个算法!
- 请问高手:关于快捷键的问题?
- 在文档类的函数中怎么才能让视图类中的OnDraw()函数运行一下?
- 问题解答:(第一个正确答案给100分)
- 谁能详细解释一下typedef CArray<CRect, CRect&> CRectArray;
- 请问编译时,出现no overload funtion take 1 parameters 是什么意思 ?
- 哪里有MFC插件框架的源码或者文章
- 如何分割CMDIFrameWnd?
- 高手看看错误是啥原因?????????
- 好想VC中每一个函数开始都是这些代码
Example/* REALLOC.C: This program allocates a block of memory for
* buffer and then uses _msize to display the size of that
* block. Next, it uses realloc to expand the amount of
* memory used by buffer and then calls _msize again to
* display the new amount of memory allocated to buffer.
*/#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>void main( void )
{
long *buffer;
size_t size; if( (buffer = (long *)malloc( 1000 * sizeof( long ) )) == NULL )
exit( 1 ); size = _msize( buffer );
printf( "Size of block after malloc of 1000 longs: %u\n", size ); /* Reallocate and show new size: */
if( (buffer = realloc( buffer, size + (1000 * sizeof( long )) ))
== NULL )
exit( 1 );
size = _msize( buffer );
printf( "Size of block after realloc of 1000 more longs: %u\n",
size ); free( buffer );
exit( 0 );
}