views:

62

answers:

1

Hello,

I am currently trying to extract a file compressed with GZip. I want to do it programmaticaly on a mobile device using Windows Mobile 6. I use the Compact Framework 3.5, and C#.

The compressed file size is about 4 MB. And the size of the original file (which is a text file) is about 42 MB. My algorithm crashes during the extraction. Each time, it crashes when the decompressed file size reachs about 33.2 MB.

Does my algorithm crash because of a file size limit ? I know that the compact framework has a memory limit of about 32 MB, but this memory limit should not be met, given that i use buffers to extract the file. Am i right ?

Here is the algorithm :

private void Extract(string GZippedFile, string TargetFile)
{
  int BUFFER_SIZE = 32768;

  using (FileStream InStream = new FileStream(GZippedFile, FileMode.Open, FileAccess.Read))
  {
    using (GZipStream GZipStream = new GZipStream(InStream, CompressionMode.Decompress))
    {
      using (FileStream OutStream =
        new FileStream(TargetFile, FileMode.Create, FileAccess.Write))
      {
        byte[] tempBytes = new byte[BUFFER_SIZE];
        int i;
        while ((i = GZipStream.Read(tempBytes, 0, tempBytes.Length)) != 0)
        {
          OutStream.Write(tempBytes, 0, i);
        }
      }
    }
  }
}

Besides, usually, when the memory limit is reached on Windows Mobile, a system message is displayed. This is not the case when this program crashes.

Also, there is enough storage memory and program memory left on the device (displayed through Settings>>Memory on the system).

Do you have any idea ?

EDIT: Sorry, I think i was wrong. In fact, this problem happened only when i am debugging the program with Visual Studio. And i am using TCp/Connect to link Visual Studio and my device.

I think the real problem is the following :

  • the file extraction take a lot of the device ressources ;

  • because the device is too busy, it can't maintain the tcp connection with Visual Studio;

  • the connection between Visual Studio and the device is lost, which make the entire program to crash without any warning to the user on the device (on the PC where Visual Studio is running, a message is displayed, warning that the connection was lost).

When i don't use the visual studio debugger, everything works just fine.

EDIT : Because of the ctackle comment, the problem does not appear anymore. The tip is to execute a

System.Threading.Thread.Sleep(1);

This instruction give the handle to visual studio during the loop and prevent the program from crashing.

A: 

Maybe consider using a 3rd party tool?

http://www.icsharpcode.net/OpenSource/SharpZipLib/

Bryan
Actually, I think the ZipStorer-Class from Codeplex is way more suited, especially since that one is Public Domain and has an extreme low footprint.
Bobby