PC Review


Reply
Thread Tools Rate Thread

BinaryFormatter and OutOfMemoryException...

 
 
Jitu
Guest
Posts: n/a
 
      11th Jan 2004
I'm really stumped on this one and would appreciate some
pointers...

I have an app that allows importing certain data in a
dataset (at which point its all in memory) and then use
BinaryFormatter to store the dataset and some more stuff
in a binary file as my application's data file. This all
works fine with smaller files, but some of the datasets
can be as large as 100 Meg when loaded in memory. The
import operation works fine, but when I try to serialize
my app's data in such a case using BinaryFormatter to
FileStream, I get a OutOfMemoryException. I have about
512M RAM. Only once was I able to write it successfully
without getting the OOM exception, and noticed that the
peak memory usage for the process went up to over a gig. I
have no idea why, and have tried a number of different
things such as explicitly specifying the target stream as
File in the context for the BinaryFormatter, but don't
seem to be able to avoid the exception.

Any thoughts on how I could handle this so that it can get
written out and read back from the file? I do want to
support 100M datasets in memory, so using SQL server, etc.
is not an option. This strictly has to be a file based
dataset.

Thanks in advance.

Jitu

 
Reply With Quote
 
 
 
 
Christian Boult
Guest
Posts: n/a
 
      12th Jan 2004
Theres an issue with serialization of big datasets, internally I think it
creates a huge amount of small objects and eventually takes up all your
memory.
Even by using the BinaryFormatter your dataset will end up serialized in
xml. Instead use DataSet.WriteXml() methods to write and ReadXml() to read
from that file. There is no problem with memory using those methods.

Chris.

"Jitu" <(E-Mail Removed)> wrote in message
news:02b301c3d7ea$4e5fb4c0$(E-Mail Removed)...
> I'm really stumped on this one and would appreciate some
> pointers...
>
> I have an app that allows importing certain data in a
> dataset (at which point its all in memory) and then use
> BinaryFormatter to store the dataset and some more stuff
> in a binary file as my application's data file. This all
> works fine with smaller files, but some of the datasets
> can be as large as 100 Meg when loaded in memory. The
> import operation works fine, but when I try to serialize
> my app's data in such a case using BinaryFormatter to
> FileStream, I get a OutOfMemoryException. I have about
> 512M RAM. Only once was I able to write it successfully
> without getting the OOM exception, and noticed that the
> peak memory usage for the process went up to over a gig. I
> have no idea why, and have tried a number of different
> things such as explicitly specifying the target stream as
> File in the context for the BinaryFormatter, but don't
> seem to be able to avoid the exception.
>
> Any thoughts on how I could handle this so that it can get
> written out and read back from the file? I do want to
> support 100M datasets in memory, so using SQL server, etc.
> is not an option. This strictly has to be a file based
> dataset.
>
> Thanks in advance.
>
> Jitu
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BinaryFormatter Tony Johansson Microsoft C# .NET 3 18th Sep 2010 02:01 AM
versioning and BinaryFormatter Tarscher Microsoft C# .NET 1 8th Oct 2008 03:21 PM
BinaryFormatter.Deserialize Igor Microsoft C# .NET 11 13th Oct 2004 09:35 AM
BinaryFormatter: portable or not? Jon Shemitz Microsoft Dot NET Framework 0 13th Oct 2004 01:16 AM
How to encrypt while using BinaryFormatter? assaf Microsoft Dot NET Framework 5 5th Oct 2004 11:43 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:46 AM.