c++将二维数组写入json文档、释放动态二维数组内存

//动态分配内存
 int** pmap=(int**)malloc(row*sizeof(int*));

    for(int i=0;i<row;++i)
    {
         pmap[i]=(int*)malloc(col*sizeof(int));
    }
//释放内存
     for(int i=0;i<row;++i)
    {
        free(pmap[i]);
    }
    free(pmap);
    pmap=nullptr;
    //规划的路径写到.json文档中
    Json::Value root;
    root["type"]=Json::Value("south_global_plan_res");
    Json::Value data;
    data["deviceSerialNumber"]=Json::Value("JY12456789321654");
    data["planId"]=Json::Value("巡检计划ID");
    Json::Value array=data["siteList"];
    cout<<"path size!!"<<Path.size()<<endl;
    for(int i=0;i<(int)Path.size();++i)
    {
        double x=Path[i]->position[1]*resolution+origin_x;
        double y=(502-Path[i]->position[0])*resolution+origin_y;
        array[i][0]=x;
        array[i][1]=y;
    }
    data["siteList"].append(array);
    root["data"]=Json::Value(data);
    Json::StyledWriter sw;
    ofstream file;
    file.open("path.json",ios::out);
    if(!file.is_open())
    {
        cout<<"error: can not find or creat !"<<endl;
    }else{
        file<<sw.write(root);
    }
    file.close();

ubuntu查看某个程序执行所占内存:

ps -A | grep test_path(test_path为程序名)//首先查询程序id

cat /proc/14410/status(查看程序所占内存,14410为程序id)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值