猿问

C++中重复调用memcpy函数,会导致内存不断增加是怎么回事?

for(int i = 0 ; i < numOfTraces ; i++){

        TraceClass *trace = new TraceClass();

        qDebug() << trace;

        printf("ii=%d,size =%d\n",i,sizeof(TraceClass));

        trace->readTraceHead(fmp);

        delete trace;

        trace = NULL;

        fmp += 240 + 4L * samples;

        progress->setValue(i+1);

        qApp->processEvents(QEventLoop::ExcludeUserInputEvents);

        if(progress->wasCanceled()){

            inLineHashMap.clear();

            xLineHashMap.clear();

            return false;

        }

    }

voidTraceClass::readTraceHead(uchar*fmp){
char*s;
longtemplong;
shorttempshort;

memcpy(&templong,fmp,4);
fmp+=4;
s=(char*)&templong;
TraceHead.TRACENUMBERLINE=BinToLong(s);//001-004
}

(1)如果把fmp +=240 + 4L * samples;注释掉,运行程序,内存不会变化很大;

(2)如果把memcpy这句话注释掉,内存不会飙升,如果不注释掉,内存上升很快达到G。

 

            请了解的大神指教


慕侠2389804
浏览 1051回答 1
1回答
随时随地看视频慕课网APP
我要回答