rexcardan / Evil-DICOM

A C# DICOM Library
168 stars 98 forks source link

Improve memory efficiency and performance #31

Closed SuneBuur closed 9 years ago

SuneBuur commented 9 years ago

These changes greatly decreases memory required when reading in large pixel data elements.

The repeated "buffer.Take(read).ToArray()" ends up creating an excessive amount of smaller arrays as it scales up its backing buffer (the TakeIterator prevents the usual optimizations). I need to process the meta data for a large amount of DICOM volumes but skipping over the pixel data element still needed about 200MB of memory for 40MB of pixel data and regrettably caused OutOfMemoryExceptions when bulk processing.

A Visual Studio 2015 diagnostic comparison: http://imgur.com/a/2OL1b