Click to See Complete Forum and Search --> : memory compression


ratheesh ravi
February 9th, 2003, 11:50 PM
hi all,
i am downloading a program to a hardware device having limited memory.
is it possible to compress different parts of the program in the device and decompress it when it is to be used?
which algorithm shall i use?
thanx in advance
ratheeshravi

galathaea
February 10th, 2003, 11:52 AM
To do this, you need to be able to separate your code into chunks that have as little coupling as possible between them. You must then be able to have an encryption/decryption engine that operates on the chunks fit in the memory and develop the rules for encryption/decryption of chunks prior to calls from one chunk to another. This is difficult in standard c++ because the language does not have a notion of the size of functions, but is possible if the c++ works directly on the machine language memory area of the code using unsafe casts and builds function pointers. However, this is only a reasonable approach if the size of the encryption/decryption engine + a decompression buffer do not make the excutable larger than the compressed version.

The proper compression algorithm depends on the instruction set of the processor you are targetting. If it is a small, fixed (N) bit instruction set, then an N-bit huffman compression could be proper (or at least compression on the operand bit size if the data bit size is a multiple).

Also note that such techniques decrease the performance of the program, which is often not acceptable for embedded devices.

mwilliamson
February 10th, 2003, 05:29 PM
If you are using WinCE or something similar, you can write most of your code in a .dll and decompress it before you dynamically load it. It is fairly simple to do.