What is the reasoning behind passing a list of ArraySegment<byte>
to Socket.BeginReceive
/SocketAsyncEventArgs
?
MSDN for the Socket.BeginReceive
constructor doesn't even correctly describe the first argument):
public IAsyncResult BeginReceive(
IList<ArraySegment<byte>> buffers,
SocketFlags socketFlags,
AsyncCallback callback,
object state
)
Paremeters:
buffers
Type:System.Collections.Generic.IList<ArraySegment<Byte>>
An array of typeByte
that is the storage location for the received data.
...
I thought that the main idea was to allocate a large buffer on the Large Object Heap, and then pass a segment of this buffer to Socket.BeginReceive
, to avoid pinning small objects around the heap and messing up GC's work.
But why should I want to pass several segments to these methods? In case of SocketAsyncEventArgs
, it seems it will complicate pooling of these objects, and I don't see the reasoning behind this.