[英]Array of Int and *Char - C++
I want to use LZO to compress a array of int or byte. 我想使用LZO压缩int或byte数组。 So I need to copy the int array to a *char then I will compress and save to file.
因此,我需要将int数组复制到* char中,然后将其压缩并保存到文件中。 And after i need do reverse operation.
在我需要做反向操作之后。 I will open the file read it with *Char and the decompress to array of int.
我将打开文件,并用* Char读取并解压缩为int数组。
I don't want to do a look in the *char to convert each int. 我不想看* char来转换每个int。 Is the any way to do this quickily?
有什么办法可以迅速做到这一点?
char *entrada;
int *arrayInt2;
int arrayInt1[100];
int ctr;
for(ctr=0;ctr<=100; ctr++)
{
arrayInt1[ctr] = ctr;
}
entrada = reinterpret_cast<char *>(arrayInt1);
arrayInt2 = reinterpret_cast<int *>(entrada);
return 0;
I want something like this. 我想要这样的东西。 Is this correct?
这个对吗? Thanks
谢谢
You can treat the integer array directly as a (binary) character buffer and pass it to your compression function: 您可以将整数数组直接视为(二进制)字符缓冲区,并将其传递给压缩函数:
char *buffer = reinterpret_cast<char *>(my_int_array);
And similarly when you decompress into a character buffer, you can use it as an integer array: 同样,当您解压缩到字符缓冲区时,可以将其用作整数数组:
int *array = reinterpret_cast<int *>(my_char_buffer);
Make sure that you keep track of the original length of the integer array and that you don't access invalid indices. 确保跟踪整数数组的原始长度,并且不要访问无效的索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.