【无标题】

linux windows 查看数组指针指向空间的长度

Windows
#include <malloc.h>

int rownum = _msize(array) / sizeof(array[0]);

linux

#include <malloc.h>
size_t malloc_usable_size(void *_ptr)

应用:

struct Structpoint
{
    int rownum;
    double* pointarr = new double();
};

Structpoint struct_temp;
void Cloud2struct(CloudType& pcloudin)
{
    int row = pcloudin.size();
    std::cout << "cloud size: " << row << std::endl;

    double* array = new double[row * 4];
    for (int i = 0; i < row; i++)
    {
        array[i * 4] = pcloudin.points[i].x;
        array[i * 4 + 1] = pcloudin.points[i].y;
        array[i * 4 + 2] = pcloudin.points[i].z;
        array[i * 4 + 3] = pcloudin.points[i].intensity;
    }

    struct_temp.rownum = malloc_usable_size(array) / sizeof(array[0]);
    struct_temp.pointarr = new double[struct_temp.rownum];
    memcpy(struct_temp.pointarr, array, malloc_usable_size(struct_temp.pointarr));
}

double* Cloud2arrone(CloudType& pcloudin)
{
    int row = pcloudin.size();
    std::cout << "cloud size: " << row << std::endl;

    double* array = new double[row * 4];
    for (int i = 0; i < row; i++)
    {
        array[i * 4] = pcloudin.points[i].x;
        array[i * 4 + 1] = pcloudin.points[i].y;
        array[i * 4 + 2] = pcloudin.points[i].z;
        array[i * 4 + 3] = pcloudin.points[i].intensity;
    }
    return array;
}
 
void Arrone2cloud(double* arrayin, int arrsize, CloudType& cloud)
{
    PointType pointout;
    for (size_t i = 0; i < arrsize; i = i + 4)
    {
        pointout.x = arrayin[i];
        pointout.y = arrayin[i + 1];
        pointout.z = arrayin[i + 2];
        pointout.intensity = arrayin[i + 3];
        cloud.push_back(pointout);
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值