I have the following to hold packets needing to be sent over a socket;
The idea of this is that my loop inside my thread will pend send_queue until it’s empty. When packets need to be sent, they’re appended to send_queue.
My concern is that I don’t know how to safely remove send_queue, and I don’t know how to safely empty the entire array in this class’ destructor.
but then I don’t know whether it’s deleted the entry, and/or freed the memory. And I’m afraid to test it, because the engine will probably crash as usual. This is not a healthy way to be working.
I don’t know whether it’s deleted all of the entries, and/or freed the memory held by each member. The documentation isn’t clear as it doesn’t provide an example with pointers.
Then I considered std::unique_ptr, but again, I can’t get my head around how that would fit in. I feel so uncomfortable when programming with this because there’s no way to know whether the memory has been freed or not until the game’s been running for a few hours and crashes for no reason because it’s leaking memory invisibly. Does anyone have any advice to help me be more confident with handling memory? I’m always worried about forgetting something and introducing a nasty, inconsistent bug.