Inherited by dynbuf.
Basically equivalent to a pair<void *, size_t>: this is just a convenient way of passing a reference to a mutable data buffer.
A databuf actually contains both a "current length" and a "maximum length" for the data buffer; for instance, one may allocate n bytes of storage, and the constructor databuf(mem, 0, n)
to reflect the fact that there is currently no data in the buffer but that it has space for a kilobyte of data. Input routines such as iohandle::read generally read up to max_length()
bytes and use set_length()
to reflect the number of bytes actually nead.
char *mem = malloc(1024); databuf buf(mem, 0, 1024); my_iohandle.read(buf); // read up to 1024 bytes cout << "I just read " << buf.length() << " bytes" << endl;
Note that a databuf may be cast to a constbuf (just as a void * can be implicitly cast to a const void *) but not vice versa.
Public Methods | |
databuf () | |
Null constructor. | |
databuf (void *dat, unsigned int len) | |
Constructs a reference to a mutable data buffer. | |
databuf (void *dat, unsigned int len, unsigned int maxlen) | |
Constructs a reference to a mutable data buffer whose size may change. | |
char * | data () |
Returns a pointer to the beginning of the data buffer. | |
void | set_length (unsigned int len) |
Modifies the length of the data buffer. | |
unsigned int | max_length () const |
Returns the maximum length of the data buffer. | |
Protected Attributes | |
unsigned int | maxlen |
|
Null constructor.
|
|
Constructs a reference to a mutable data buffer. Both its current length and maximum length are len. |
|
Constructs a reference to a mutable data buffer whose size may change.
|
|
Returns a pointer to the beginning of the data buffer.
|
|
Returns the maximum length of the data buffer.
|
|
Modifies the length of the data buffer.
|
|
|