I am not sure you gain anything here. For starters, if I am getting this
correctly, you want to do the following:
Socket client = serversocket.Accept();
myhandlelist.Add(client.Handle);
and then you will use the IntPtr from then on.
First notice, that you are storing the native handle. That means the OS
resources backing the socket have already been allocated. So, the most you
are saving is managed memory on the GC.
You might want to rethink the architecture of your application to make sure
you are using resources efficiently. For example, if your connections are
longlived (session oriented) then you might want to keep the connections
around for a certain amount of time. This involves coming up with a
connection management algorithm, whereby you time out and close idle
connections etc. However you will have to weigh the potential gain in
performance with respexct to the efffort involved in
designing/implementing/debugging such a scheme.
--
Thanks
feroze
=============
This posting is offered as-is. It offers no warranties and confers no
rights.
"Paul W" <an*******@yahoo.com> wrote in message
news:f_vzc.11594$wS2.10639@okepread03...
Nevermind... this way loses the reference to the socket, so it is not a
good alternative.
"Paul W" <an*******@yahoo.com> wrote in message
news:Ykqzc.11501$wS2.4327@okepread03... I have a socket-based app running that spawns a different socket for
each user and I was looking for a way to optimize it a little better.
Currently I keep a collection of active sockets (300 - 400). My plan was
to capture the Socket IntPtr Handle when they connect and then each time I
needed to send information to that particular socket, I would call the
private Socket constructor via Reflection and use the IntPtr value as
the handle parameter. I would be maintaining a collection of 32 bit values
rather than a collection of Sockets.
My question is... do I gain anything by doing this? (1) Is reflection
fast enough in this instance. (2) Do I really get any type of performance
gain by storing the handle and not the object?
Thanks.