TArray<uint8*> memory handling

I have the following to hold packets needing to be sent over a socket;


TArray<uint8*> send_queue;

The idea of this is that my loop inside my thread will pend send_queue[0] until it’s empty. When packets need to be sent, they’re appended to send_queue.
(concurrency concerns?)

My concern is that I don’t know how to safely remove send_queue[0], and I don’t know how to safely empty the entire array in this class’ destructor.

I could


delete send_queue[0]

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.

Likewise, with


send_queue.Empty()

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.

What’s wrong with TArray<TArray<uint8>>? TArray<T> has a GetData() function that will return const T* pointing at the data, and you can always do &Array[0] if you need a mutable pointer. Don’t manually manage memory if you don’t absolutely have to.