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.
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