nmangue / NGrib

NGrib is a .NET library to read GRIB (GRid in Binary) files. GRIB is a gridded data standard from WMO (World Meteorological Organisation) and is used by many meteorological organisation. Fork of GribCS.
GNU Lesser General Public License v3.0
17 stars 10 forks source link

Changed the BufferedBinaryReader to using pooled arrays #11

Closed ArnimSchinz closed 8 months ago

ArnimSchinz commented 1 year ago

Instead of allocating a new buffer on every file, one can (re)use pooled arrays. There is a good Shared ArrayPool implementation inside System.Buffers, which can be used for this purpose. There should not be a memory-leak in case the buffer is not returned to the pool, so the Dispose() method is enough and no destructor is needed. The array returned by the pool could be larger than the requested size, since the size will always be a power of 2. This is why the buffersize is derived from the length of the returned array. This change only affects 4 lines, I don't know why it shows such a large difference.

nmangue commented 8 months ago

Hello Arnim ! Thank you for your contribution