悬而未决的问题!
zhubo 2001-11-27 04:32:13 现有一问题请教:
我要实现的功能是把接收的数据或者视频流存为文件.
这些数据或者视频流从串口发出,经过Rabbit转为TCP/IP格式.
考虑到接收到的数据量或者视频流可能很大,我采用的是分批保存的办法.
基本代码如下:
.h文件:
...
#define maxlength 1000000
BYTE *pBuffer;
BYTE *pTemp;
int count;
...
.cpp文件:
...
pBuffer=new BYTE[maxlength]; //alloc the memory
memset(pBuffer,0,maxlength); //init the memory
pTemp=pBuffer;
count=maxlength;
...
int nReceived;
char buf[1000];
memset(buf,0,sizeof(buf));
nReceived=sock.Received((BYTE *)buf,sizeof(buf)); //receive the data
memcpy(pTemp,buf,nReceived); //fill the memory
pTemp += nReceived; //move the pointer
count -= nReceived;
if(count < 1000 )
{
if(...//need save)
{
...
WriteFile(m_hFile,pBuffer,(maxlength - count),...); //save it
...
}
memset(pBuffer,0,maxlength); //clear the memory
count=maxlength;
...
}
...
...
delete pBuffer;
...
编译的时候没有错误,但是运行或者调试的时候总是非法操作,错误代码如下:
Unhandled exception in **.exe:ox00000005:Access violation(对话框中内容)
请问这是否是maxlength过大或者内存小导致的.(内存32M)
换台内存高的机器,通过.(256M)
不应该是因为内存小啊,我才分配了1M的地方呀?请给予指点.多谢!