0

I want to use LZO to compress a array of int or byte. So I need to copy the int array to a *char then I will compress and save to file. And after i need do reverse operation. I will open the file read it with *Char and the decompress to array of int.

I don't want to do a look in the *char to convert each 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

p.magalhaes
  • 7,595
  • 10
  • 53
  • 108
  • 1
    What is a `*char`? Do you mean `char*`? Consider starting by getting a [good introductory C++ book](http://stackoverflow.com/questions/388242/the-definitive-c++-book-guide-and-list). – James McNellis Dec 13 '10 at 00:57

1 Answers1

1

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.

casablanca
  • 69,683
  • 7
  • 133
  • 150