This class manages the allocation of byte buffers.
For a list of all members of this type, see BufferProvider Members.
System.Object
InfiniTec.SystemUtilities.BufferProvider
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.
Normally, one would simply do a byte[] buffer = new byte[1000000]
. While this is not entirely a bad idea, it certainly can become one when you do this often enough, because your memory consumption rise with each request, even if you don't have any references to the arrays any longer.
The reasons for this is that such large objects are stored on the Large Object Heap. The objects on this heap will eventually be gargabe collected, but this will occour only when the runtime does a full collection. Which will hopefully not occur so often as it is a quite expensive procedure.
This class allows you to re-use previously allocated buffers via the GetBuffer method. And once you are done with the buffer you can safely return it by using RecycleBuffer.
Note that this manager does not prevent the garbage collection from collecting these recycled buffers, since they are stored within a WeakReference
Namespace: InfiniTec.SystemUtilities
Assembly: InfiniTec.SystemUtilities.BufferProvider (in InfiniTec.SystemUtilities.BufferProvider.dll)
BufferProvider Members | InfiniTec.SystemUtilities Namespace