hey guys, here's the issue,
Essentially, I have a very large List containing in turn relatively large Dictionaries
So basically, I have a very big in memory collection.
I then serialize this collection manually to XML, and send it over http. needless to say, the XML is too large, sometimes so large I get an OutOfMemory exception before even trying to send it.
In .NET, how would I go about calculating potential memory usage. For example, in this case, I have to break down the XML into chunks, by processing only small amounts of the Collection at a time.
How do I efficiently calculate the size of each "chunk" on-the-fly. I don't want to pick an arbitrary number like, "process 100 items at any one time", I want to know, approximately, how big each chunk should be for a case by case basis.
cheers
UPDATE
Although @Jacob provided the best solution for this particular problem, the conceptual structure of the app is itself flawed.
Indeed, the solution is to execute a fraction of your message, in order to calculate how potentially big the message will be, when working with a collection.
You then send each acceptably sized unit, one by one.
But this is only a hack. The real solution is to either find a way to not pass large messages, or use a completely different protocol altogether.
There's an interesting post on the subject here though if you want to use SOAP, however I decided to find a way around sending so much data.