qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Blue Swirl <blauwirbel@gmail.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] Wire g_new() and friends to the qemu_malloc() family
Date: Fri, 19 Aug 2011 08:22:54 -0700	[thread overview]
Message-ID: <4E4E7FCE.5050108@redhat.com> (raw)
In-Reply-To: <CAFEAcA8Hfqp0SHsnZ5UPP64b46StzvXLSMAUJWUut4vHBer8HQ@mail.gmail.com>

On 08/18/2011 09:54 PM, Peter Maydell wrote:
> On 18 August 2011 18:48, Avi Kivity<avi@redhat.com>  wrote:
> >  +static GMemVTable gmemvtable = {
> >  +    .malloc = qemu_malloc,
> >  +    .realloc = qemu_realloc,
> >  +    .free = qemu_free,
> >  +};
> >  +
> >  +/**
> >  + * qemu_malloc_init: initialize memory management
> >  + */
> >  +void qemu_malloc_init(void)
> >  +{
> >  +    g_mem_set_vtable(&gmemvtable);
> >  +}
>
> Does this mean you can now safely allocate with g_malloc
> and free with qemu_free, or is mixing the two APIs like that
> still a no-no ?

You can, but I'd forbid it.  Mixing layers can only lead to tears later on.

Best would be to convert qemu_malloc()s to g_new()s and g_malloc()s to 
reduce confusion.

>
> (I'm thinking about a situation where you might use a glib utility
> function that returned g_malloc'd memory and want to pass that back
> to your caller without having to either copy to qemu_malloc'd memory
> or require your caller to care about the distinction.)
>

Changing ownership of memory is rare, I hope.

-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.

  reply	other threads:[~2011-08-19 15:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-18 17:48 [Qemu-devel] [PATCH] Wire g_new() and friends to the qemu_malloc() family Avi Kivity
2011-08-19  4:25 ` Stefan Hajnoczi
2011-08-19  4:54 ` Peter Maydell
2011-08-19 15:22   ` Avi Kivity [this message]
2011-08-20  6:59     ` Blue Swirl
2011-08-21  3:11       ` Anthony Liguori
2011-08-21  7:17         ` Blue Swirl
2011-08-21 13:24           ` Anthony Liguori
2011-08-22  6:53             ` Paolo Bonzini
2011-08-21  3:40 ` Anthony Liguori

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=4E4E7FCE.5050108@redhat.com \
    --to=avi@redhat.com \
    --cc=blauwirbel@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /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;
as well as URLs for NNTP newsgroup(s).