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);
}
}