From: Paolo Bonzini <pbonzini@redhat.com>
To: "Spensky, Chad - 0559 - MITLL" <chad.spensky@ll.mit.edu>
Cc: Wolfgang Richter <wolf@cs.cmu.edu>,
Stefan Hajnoczi <stefanha@gmail.com>, Fam Zheng <famz@redhat.com>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>
Subject: Re: KVM Block Device Driver
Date: Sun, 18 Aug 2013 16:04:16 +0200 [thread overview]
Message-ID: <5210D460.8060708@redhat.com> (raw)
In-Reply-To: <CE31474C.E079%chad.spensky@ll.mit.edu>
Il 14/08/2013 20:44, Spensky, Chad - 0559 - MITLL ha scritto:
> Wolfgang,
>
> Thanks so much for the response. It turns out that wasn't handling the
> QEMUIOVector properly. When I first implemented it, I saw that the iovec
> was a pointer and assumed that there would only ever be one. Given the
> lack of documentation and my lack of understanding this went undetected
> for a while. everything now seems to work just fine. :-) See below for
> the portion of code that threw me off. Thanks again!
>
> - Chad
>
>
> Proposed change to qemu-common.h (:
>
> typedef struct QEMUIOVector {
> struct iovec *iov;
> int niov;
> int nalloc;
> size_t size;
> } QEMUIOVector;
>
> changed to:
>
> // Array of I/O vectors
>
> typedef struct QEMUIOVector {
> struct iovec iov[];
> int niov;
> int nalloc;
> size_t size;
> } QEMUIOVector;
This wouldn't work. As you wrote it, it wouldn't even compile.
Embedding an array is possible if you place it at the end of the struct,
but then it is not possible to resize the array (because when you
reallocate it, the containing QEMUIOVector could move in memory and any
pointers to the containing QEMUIOVector would become invalid).
In C, a dynamically-allocated array is represented by a pointer to the
first item. The size of the array and the size of the
dynamically-allocated memory block are stored together with the pointer
(in this case, in the niov and nalloc members).
In fact, whenever you see something like "iovec iov[]" in Java, what's
being stored in memory is exactly a pointer to the first item, the size
of the array and the size of the dynamically-allocated memory block. C
just makes that explicit.
Paolo
next prev parent reply other threads:[~2013-08-18 14:05 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-13 20:13 KVM Block Device Driver Spensky, Chad - 0559 - MITLL
2013-08-14 2:40 ` Fam Zheng
2013-08-14 10:05 ` Stefan Hajnoczi
2013-08-14 11:29 ` Spensky, Chad - 0559 - MITLL
2013-08-14 12:16 ` Fam Zheng
2013-08-14 12:19 ` Spensky, Chad - 0559 - MITLL
2013-08-14 12:35 ` Fam Zheng
2013-08-14 14:07 ` Stefan Hajnoczi
2013-08-14 14:40 ` Wolfgang Richter
2013-08-14 14:43 ` Spensky, Chad - 0559 - MITLL
2013-08-14 15:02 ` Wolfgang Richter
2013-08-14 15:49 ` Wolfgang Richter
2013-08-14 18:44 ` Spensky, Chad - 0559 - MITLL
2013-08-14 19:42 ` Wolfgang Richter
2013-08-18 14:04 ` Paolo Bonzini [this message]
2013-08-18 14:48 ` Wolfgang Richter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5210D460.8060708@redhat.com \
--to=pbonzini@redhat.com \
--cc=chad.spensky@ll.mit.edu \
--cc=famz@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=stefanha@gmail.com \
--cc=wolf@cs.cmu.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox