I need to save packet state for a while.
So I read the packet data which is represented as unsigned char* and than I create a record with this data and save the record in the list for a while.
Which will be a better way to represent the packet in the record as char* or as char[].
How do i copy the read data ( unsigned char ) to both options :
To unsigned char[] and to unsigned char*
I need to copy the data because each time I read packet it will be readed to the same char*,so when I save it for a while I need to copy data first
If the packet data is binary I’d prefer using
std::vectorto store the data, as opposed to one of the CstrXXXfunctions, to avoid issues with a potential NULL character existing in the data stream. MoststrXXXfunctions look for NULL characters and truncate their operation. Since the data is not a string, I’d also avoidstd::stringfor this task.The vector constructor will copy all the data from
buf[0]tobuf[datalen - 1]and will deallocate the memory when the vector goes out of scope. You can get a pointer to the underlying buffer usingv.data()or&v[0].