- what is the design rationale for allowing the non-const view to modified original IOVector? IT seem very counter-intuitive for a view to modify original data. That make me very confused.
void DeepCopyIOVe(IOVector* src, IOVector* dest) {
dest->memcpy_from(src, src->sum);
std::string s;
s.resize(dest->sum());
dest.memcpy_to(s.data(), dest->sum());
// dest actually deep copy all bytes from src but iov_len equal 0 which mean dest->sum is also 0 and s is "".
// if want to use these two variables properly late on, I had to use const IOVector* value to memcpy,
// like static_cast<const IOVector*>(dest)->memcpy_from(static_cast<const IOVector*>dest(src), src->sum()).
}
the reason why sum equal to 0 is that func implementation internally uses by a view object. It can directly access the underlying iovec* iovec() which should only exclusively managed by IOVector Itself.
- are there similar patterns in other libraries? Or that is unique to photonLibOS?