By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,670 Members | 1,558 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,670 IT Pros & Developers. It's quick & easy.

Out of memory

P: n/a
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.
Jun 27 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.
Jun 27 '08 #2

P: n/a
On Jun 27, 10:19*am, "Ignacio Machin ( .NET/ C# MVP )"
<ignacio.mac...@gmail.comwrote:
On Jun 27, 2:23*am, CSharper <cshar...@gmx.comwrote:
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("items.resources",
FileMode.OpenOrCreate, FileAccess.Write);

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

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

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

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

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

// Write the resources to the stream, and close it.
writer.Close();
}
Jun 27 '08 #3

P: n/a
On Jun 27, 3:35*pm, CSharper <cshar...@gmx.comwrote:
On Jun 27, 10:19*am, "Ignacio Machin ( .NET/ C# MVP )"

<ignacio.mac...@gmail.comwrote:
On Jun 27, 2:23*am, CSharper <cshar...@gmx.comwrote:
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("items.resources",
* * * *FileMode.OpenOrCreate, FileAccess.Write);

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

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

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

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

* * * * * * // Add resources to the resource writer.
* * * * * * writer.AddResource("String 4", "Fourth String");
* * * * * * writer.AddResource("String 5", "Fifth String");
* * * * * * writer.AddResource("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("items.resources",
FileMode.OpenOrCreate, FileAccess.Write);

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

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

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

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

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

// Write the resources to the stream, and close it.
writer.Generate();
writer.Close();
fs.Dispose();
fs.Close();
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.