Captain! I think she's leaking memory
-
ok, good people..i have a following line of code.. using( MemoryStream mStr = new MemoryStream( ) ) { try { mStr.Capacity = totalByteCount ; } } Of course the dude i got inherited this code from is trying to put 141372000 in the memory buffer i.e the capacity. At this point i get the following error Exception of type System.OutOfMemoryException was thrown." } I am at a total loss. Have tried different things...So i throw a hail mary over to the code porject dudes. Thanks for your help Sameer
-
ok, good people..i have a following line of code.. using( MemoryStream mStr = new MemoryStream( ) ) { try { mStr.Capacity = totalByteCount ; } } Of course the dude i got inherited this code from is trying to put 141372000 in the memory buffer i.e the capacity. At this point i get the following error Exception of type System.OutOfMemoryException was thrown." } I am at a total loss. Have tried different things...So i throw a hail mary over to the code porject dudes. Thanks for your help Sameer
Isn't it possible just use the following code:
using(MemoryStream stream = new MemoryStream()) { for(int i= 0; i < totalByteCount; i++) { stream.Write(new byte[] { 0 },0,1); //Not sure about this call, haven't got the docs here and I'm too lazy to remember :P } stream.Seek(0,...); }
This simply fills the stream with zeroes and resets the stream to the beginning. This way the capacity is set to the right value automatically, plus the stream is really that size. -- EDIT: Hmm, I'm sleeping again ;P I tried the code and it seems to me that you are indeed short of memory for this action.WM. What about weapons of mass-construction?
-
ok, good people..i have a following line of code.. using( MemoryStream mStr = new MemoryStream( ) ) { try { mStr.Capacity = totalByteCount ; } } Of course the dude i got inherited this code from is trying to put 141372000 in the memory buffer i.e the capacity. At this point i get the following error Exception of type System.OutOfMemoryException was thrown." } I am at a total loss. Have tried different things...So i throw a hail mary over to the code porject dudes. Thanks for your help Sameer
If you really need to write 141MB worth into a stream, perhaps the hard drive is a better location (i.e. FileStream) rather tha RAM memory (i.e. MemoryStream).
Tech, life, family, faith: Give me a visit. I'm currently blogging about: For Christians: The Significance of Yom Teruah The apostle Paul, modernly speaking: Epistles of Paul Judah Himango