The socket classes in .NET have got some new async methods (like Socket.ReceiveAsync
).
I'm trying to understand their purpose. As I understand it, they were created to avoid making a new IAsyncResult
object for each operation.
Let's say that I were to create a high performance HTTP server. Then I need to create a Request or a Response object for each operation. And the request or response objects certainly have some properties that might be other classes too (or just primitives + string). And I might have to fetch information from a database (more objects to create).
My point is that quite many objects can be created per request/reply. Is the AsyncResult
objects so heavy that it would affect performance of a complete server? Or do MS mean that I should use flyweight pattern (reusing request/reply objects instead of allocating new ones) for all my objects in the server ?
Please enlighten me.
Update
From MSDN about the new Async methods:
The main feature of these enhancements is the avoidance of the repeated allocation and synchronization of objects during high-volume asynchronous socket I/O. The Begin/End design pattern currently implemented by the System.Net.Sockets.Socket class requires a System.IAsyncResult object be allocated for each asynchronous socket operation
Source: http://msdn.microsoft.com/en-us/library/system.net.sockets.socketasynceventargs.aspx
Update2
This question is not a duplicate. I'm not asking about the difference. I'm well aware of the difference. If they added the methods to reduce allocations and the work for the GC, should I do the same in my protocol layer on top of the socket handling? i.e. should I use the flyweight pattern for objects like HttpReqest
etc.