I'm sort of surprised an allocation occurs every time the heartbeat is sent. That is a lot of trips to the heap.<p>I'm not very familiar with how TLS heartbeats are implemented, but I wonder if the buffer could have just been alloc'd once when the connection was created.