Out of memory

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CSharper

    Out of memory

    I have a resource file that i open to write.After writing almost 300MB
    I call the close method and It failed with out of memory. One thing I
    learned that, in C#, resource writers doesn't write data directly to
    disk instead it writes to memory and then at the end on either close/
    dispose, it will write the data to disk. I am thinking of compressing
    the data still, I will grow into the size very fast.
    Is there an alternate solution to this? Other than compressing the
    data file?
    Thanks.
  • =?utf-8?Q?David_Fi=C5=A1er?=

    #2
    Re: Out of memory

    Well if is it dedicated from Stream there could be a Flush() method. It
    flushes the buffer and write data directly..
    >I have a resource file that i open to write.After writing almost 300MB
    I call the close method and It failed with out of memory. One thing I
    learned that, in C#, resource writers doesn't write data directly to
    disk instead it writes to memory and then at the end on either close/
    dispose, it will write the data to disk. I am thinking of compressing
    the data still, I will grow into the size very fast.
    Is there an alternate solution to this? Other than compressing the
    data file?
    Thanks.
    >

    Comment

    • CSharper

      #3
      Re: Out of memory

      On Jun 27, 10:19 am, "Ignacio Machin ( .NET/ C# MVP )"
      <ignacio.mac... @gmail.comwrote :
      On Jun 27, 2:23 am, CSharper <cshar...@gmx.c omwrote:
      >
      I have a resource file that i open to write.After writing almost 300MB
      I call the close method and It failed with out of memory. One thing I
      learned that, in C#, resource writers doesn't write data directly to
      disk instead it writes to memory and then at the end on either close/
      dispose, it will write the data to disk.  I am thinking of compressing
      the data still, I will grow into the size very fast.
      Is there an alternate solution to this? Other than compressing the
      data file?
      Thanks.
      >
      Hi,
      >
      How are you writing it?
      You can always call flush, but I doubt that the buffer is that big,
      post some code please
      Here is the simple code I have used to resolve the out of memory
      issue. I thought I will close and reopen the resource to append. But
      it seems, the append part doesn't work. It doesn't throw any exception
      but it does not write the file. What could be the problem?
      static void Main(string[] args)
      {
      FileStream fs = new FileStream("ite ms.resources",
      FileMode.OpenOr Create, FileAccess.Writ e);

      // Open a resource writer to write from the stream.
      IResourceWriter writer = new ResourceWriter( fs);

      // Add resources to the resource writer.
      writer.AddResou rce("String 1", "First String");
      writer.AddResou rce("String 2", "Second String");
      writer.AddResou rce("String 3", "Third String");

      // Write the resources to the stream, and close it.
      writer.Close();
      fs = new FileStream("ite ms.resources",
      FileMode.Append , FileAccess.Writ e);

      // Open a resource writer to write from the stream.
      writer = new ResourceWriter( fs);

      // Add resources to the resource writer.
      writer.AddResou rce("String 4", "Fourth String");
      writer.AddResou rce("String 5", "Fifth String");
      writer.AddResou rce("String 6", "Sixth String");

      // Write the resources to the stream, and close it.
      writer.Close();
      }

      Comment

      • CSharper

        #4
        Re: Out of memory

        On Jun 27, 3:35 pm, CSharper <cshar...@gmx.c omwrote:
        On Jun 27, 10:19 am, "Ignacio Machin ( .NET/ C# MVP )"
        >
        >
        >
        >
        >
        <ignacio.mac... @gmail.comwrote :
        On Jun 27, 2:23 am, CSharper <cshar...@gmx.c omwrote:
        >
        I have a resource file that i open to write.After writing almost 300MB
        I call the close method and It failed with out of memory. One thing I
        learned that, in C#, resource writers doesn't write data directly to
        disk instead it writes to memory and then at the end on either close/
        dispose, it will write the data to disk.  I am thinking of compressing
        the data still, I will grow into the size very fast.
        Is there an alternate solution to this? Other than compressing the
        data file?
        Thanks.
        >
        Hi,
        >
        How are you writing it?
        You can always call flush, but I doubt that the buffer is that big,
        post some code please
        >
        Here is the simple code I have used to resolve the out of memory
        issue. I thought I will close and reopen the resource to append. But
        it seems, the append part doesn't work. It doesn't throw any exception
        but it does not write the file. What could be the problem?
        static void Main(string[] args)
                {
                    FileStream fs = new FileStream("ite ms.resources",
               FileMode.OpenOr Create, FileAccess.Writ e);
        >
                    // Open a resource writer to write from the stream.
                    IResourceWriter writer = new ResourceWriter( fs);
        >
                    // Add resources to the resource writer.
                    writer.AddResou rce("String 1", "First String");
                    writer.AddResou rce("String 2", "Second String");
                    writer.AddResou rce("String 3", "Third String");
        >
                    // Write the resources to the stream, and close it.
                    writer.Close();
                    fs = new FileStream("ite ms.resources",
               FileMode.Append , FileAccess.Writ e);
        >
                    // Open a resource writer to write from the stream.
                    writer = new ResourceWriter( fs);
        >
                    // Add resources to the resource writer.
                    writer.AddResou rce("String 4", "Fourth String");
                    writer.AddResou rce("String 5", "Fifth String");
                    writer.AddResou rce("String 6", "Sixth String");
        >
                    // Write the resources to the stream, and close it.
                    writer.Close();
                }- Hide quoted text -
        >
        - Show quoted text -
        Here is the correct code, sorry

        FileStream fs = new FileStream("ite ms.resources",
        FileMode.OpenOr Create, FileAccess.Writ e);

        // Open a resource writer to write from the stream.
        IResourceWriter writer = new ResourceWriter( fs);

        // Add resources to the resource writer.
        writer.AddResou rce("String 1", "First String");
        writer.AddResou rce("String 2", "Second String");
        writer.AddResou rce("String 3", "Third String");

        // Write the resources to the stream, and close it.
        writer.Generate ();
        writer.Close();
        fs.Dispose();
        fs.Close();
        fs = new FileStream("ite ms.resources",
        FileMode.Append , FileAccess.Writ e);

        // Open a resource writer to write from the stream.
        writer = new ResourceWriter( fs);

        // Add resources to the resource writer.
        writer.AddResou rce("String 4", "Fourth String");
        writer.AddResou rce("String 5", "Fifth String");
        writer.AddResou rce("String 6", "Sixth String");

        // Write the resources to the stream, and close it.
        writer.Generate ();
        writer.Close();
        fs.Dispose();
        fs.Close();

        Comment

        Working...