CODE:
struct Stringdata
{
// Length of data in buffer.
size_t len;
// Allocated size of buffer.
size_t alc;
// Buffer.
char data[1];
};
typedef std::list<Stringdata*> Stringdata_list;
Stringdata_list strings_;
Stringdata *psd = this->strings_.front();
//...
if (len > psd->alc - psd->len)
alc = sizeof(Stringdata) + buffer_size;
else
{
char* ret = psd->data + psd->len;
memcpy(ret, s, len - sizeof(Stringpool_char));
memset(ret + len - sizeof(Stringpool_char), 0,
sizeof(Stringpool_char));
psd->len += len;
return reinterpret_cast<const Stringpool_char*>(ret);
}
In the code sample above, I have confused about the operations in the else
branch.
Does it create a new element and insert it after the front element or just place a new element after within the first element of list?