Greg, I meant to chime in on this earlier...  I'm currently waiting for
further clarification of documentation from Microsoft for WSASend[To]
(which is eventually used by Socket.BeginSend).  What I've gotten from
Microsoft so far is that the memory given to WSASend, when asynchronous
(overlapped I/O), is copied (referred to as "capture" in the WSASend
documentation) before being returned from WSASend.  As far as I can tell,
Socket.BeginSend also makes a copy of the memory it's asked to send, pins
it, then gives it to WSASend.  If what I'm hearing from MS abount WSASend
and the "service provider's responsibility to capture [the buffer] ...
before returning from [the call to WSASend]" is true, it seems redundant
to copy these buffers and pin the copies if the buffer need only exist for
the duration of the WSASend call--unless they know something they're not
willing to tell.  I was under the impression that memory assigned to a
reference can't move while it's being used in a method call, especially a
PInvoked call.  Although it would be fairly trivial to test if the above
is false (but wouldn't be conclusive if not proven to be false), I haven't.

I don't know if your focus is mainly receive rather than send; but, I
thought the above might be of interest...

On Tue, 1 Aug 2006 17:15:47 -0400, gregory young <[EMAIL PROTECTED]>
wrote:

>Ok so I think everyone can agree that creating buffers on the fly in
>an async socket server is bad ... there is alot of literature
>available on the problems this will cause with the heap. I am looking
>at a few options to get around this.
>
>1) Have a BufferPool class that hands out ArraySegment<byte> portions
>of a larger array (large enough that it would be in the LOH). If all
>of the array is used create another big segment.
>
>2) Create a bunch of smaller arrays for use by the bufferpool class
>and have it hand them back
>
>In both 1 & 2 I would probably have the connection use their buffer
>for the duration of the connection. I would internally hold a list of
>the free blocks. When a connection was done ith its buffer it would
>have to release it back to this pool. My thought is that #2 might be
>better for dealing with cases where I want to shrink the number of
>buffers allocated from the previous maximum if needed.
>
>In general I lean towards #1 ... but figured I would check if I might
>be missing something.

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to