I have been working with boost::asio for a while, and although I understand the concept of asynchronous calls, I am still somewhat stunned by the consequences of memory management. In ordinary synchronous code, the lifetime of an object is clear. But consider a scenario similar to the daily server case:
There may be several active connections that were accept ed. Each connection now sends and receives some data from the socket, does some work internally, and then decides to close the connection. It is safe to assume that the data associated with the connection should remain available during processing, but memory may be freed as soon as the connection is closed. But how can I properly create / destroy data? Assuming I use class es and associate the callback with member functions, should I create a class with new and call delete this; once the processing is complete or is there a better way?
hfhc2 source share