0

我最近在 g++ 4.4.6 中测试了 fastflow,下面是一个相当简单的测试:

using namespace ff ;
int g1=0 ;

class Stage1 : public ff_node{
public :
    void *svc(void *task){
        g1++ ;
        if(g1 >= 10000)
        {
            return NULL ;
        }
        char *p=(char*) calloc(sizeof(char),10) ;
        return ((void*)p) ;
    }
} ;
class Stage2 : public ff_node{
public :
    void *svc(void *task){
        free(task) ;
        return GO_ON ;
    }
} ;

int main(int agrc,char *argv[])
{
    ff_pipeline pipe ;
    pipe.add_stage(new Stage1()) ;
    pipe.add_stage(new Stage2()) ;

    for(int idx=0;idx<1000000;idx++)
    {
        g1 = 0 ;
        if(pipe.run_and_wait_end() <0){
            error("running pipeline\n");
            return -1 ;
        }
        printf("idx=(%d)\n",idx) ;
    }
    return 0 ;
}

这个测试很简单,但是我在linux中观察内存使用情况,我发现“VIRT”和“RES”在增加,我不明白,因为Stage1分配了内存,Stage2会释放它,很简单实施,请问我在这个测试样本中遗漏了什么?!

编辑 :

class Stage1 : public ff_node{
public :
    void *svc(void *task){
        g1++ ;
        if(g1 >= 10000)
        {
            return NULL ;
        }
        //char *p=(char*) calloc(sizeof(char),10) ;
        //return ((void*)p) ;
        std::auto_ptr<char> x(new char(10)) ;
        return ((void*)x.get()) ;
    }
} ;
class Stage2 : public ff_node{
public :
    void *svc(void *task){
        //free(task) ;
        return GO_ON ;
    }
} ;

使用 auto_ptr 仍然会遇到同样的问题....

4

0 回答 0