char vector is good because memory is contiguous. Therefore, you can use it with a large number of C APIs such as berkley sockets or file APIs. You can do the following, for example:
std::vector<char> vect; ... send(sock, &vect[0], vect.size());
and it will work fine.
You can essentially treat it the same as any other dynamically allocated char buffer. You can scan up and down in search of magic numbers or patterns. You can disassemble it partially in place. To get from a socket, you can easily resize it to add more data.
The disadvantage is resizing is not very efficient (resizing or prejudice is prudent), and removal from the front of the array will also be very uncertain. If you need to, say, put only one or two characters at a time in front of the data structure very often, copying them to deque before this processing can be an option. It costs you a copy, and deque memory does not touch, so you cannot just pass a pointer to the C API.
Below, learn about data structures and their trade-offs before diving, however the char vector is usually what I see in normal practice.
Doug T. Jan 13 '09 at 23:02 2009-01-13 23:02
source share