Now, what strategies can be implemented to support a large package of such buffers, how should I process them, how can I avoid a performance penalty, etc. ??
It's hard to know the answer without knowing more about your particular design. In general, I would not support my own "buffer bag" and instead used the OS built into the buffer bag - a bunch.
But anyway, what I would do in the general case is an interface for callers of your code that reflect what WSASend does for overlapping i / o. For example, suppose you provide an interface for sending a specific structure:
struct Foo { int x; int y; };
I would require SendFoo users to allocate a Foo instance with a new one and tell them that after calling SendFoo, the memory no longer “belongs” to its code, and therefore they should not use it.
You can enhance this even further with a little trickery:
This allows the SendFoo body to send the memory address to WSASend, but change the pointer passed to NULL, separating the connection between the calling code and their memory. Of course, you cannot know exactly what the caller is doing with this address; they may have a copy elsewhere.
This interface also provides that with each WSASend one block of memory will be used. You are really stepping into more than dangerous territory, trying to split one buffer between two WSASend calls.
source share