On Tue, Jan 29, 2019 at 6:24 PM Vladimir Sementsov-Ogievskiy <vsement...@virtuozzo.com> wrote: > 29.01.2019 6:31, Stefan Hajnoczi wrote: > > On Fri, Jan 25, 2019 at 07:46:01PM +0300, Vladimir Sementsov-Ogievskiy > > wrote: > Hmm. In this case we definitely will have tiny extra memory usage, but we > gain beautiful > readability. > > So, like this: > > diff --git a/include/qemu/iov.h b/include/qemu/iov.h > index 5f433c7768..53de1b38bb 100644 > --- a/include/qemu/iov.h > +++ b/include/qemu/iov.h > @@ -134,9 +134,31 @@ typedef struct QEMUIOVector { > struct iovec *iov; > int niov; > int nalloc; > - size_t size; > + union { > + struct { > + void *__unused_iov_base;
This could be struct iovec *iov for nalloc > 0 users. Must resist hackiness! :) > + size_t size; > + }; > + struct iovec local_iov; > + }; > } QEMUIOVector; That's clever and not too hacky. Please include a comment so the intent is clear: /* Save space by reusing the embedded iovec's size field as the total size field. Users with external iovecs don't use the embedded iovec so this is safe. */ Stefan