large data - Exception of type 'System.OutOfMemoryException' was thrown. C# when using Memory stream -


i working wpf application , memory stream write method used in write dicom data bytes.it shows exception of type system.outofmemoryexception when try write big dicom data having size more 70 mb. can please suggest solution resolve this.

the piece of code

try             {                 using ( memorystream imagememorystream = new memorystream())                 {                     while (true)                     {                         // retrieve dicomdata.                         // data comes chunks; if file size larger, multiple retrievedicomdata() calls                         // has raised. return value specifies whether chunk last 1 or not.                                           dicomdata = dicomservice.retrievedicomdata( hierarchyinfo );                         imagememorystream.write( dicomdata.databytes, 0, dicomdata.databytes.length );                         if (dicomdata.islastchunk)                         {                             // data smaller; completed reading so, end                             break;                         }                     }                     imagedata=imagememorystream.toarray();                 }                 return imagedata;             }             catch( exception exception )             {                 throw new dataexception( exception.stacktrace );             } 

it quite common memorystream throw outofmemoryexceptions due lack of contiguous (not total) memory available. there number of alternate implementations lessen problem. take @ memorytributary example.

or, depending on needs, try writing direct storage instead of memory.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -