From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:36699) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QuQuY-0007Jh-1S for qemu-devel@nongnu.org; Fri, 19 Aug 2011 11:23:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QuQuW-0003Hc-Vj for qemu-devel@nongnu.org; Fri, 19 Aug 2011 11:23:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:19777) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QuQuW-0003HR-L3 for qemu-devel@nongnu.org; Fri, 19 Aug 2011 11:23:04 -0400 Message-ID: <4E4E7FCE.5050108@redhat.com> Date: Fri, 19 Aug 2011 08:22:54 -0700 From: Avi Kivity MIME-Version: 1.0 References: <1313689697-23627-1-git-send-email-avi@redhat.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] Wire g_new() and friends to the qemu_malloc() family List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Blue Swirl , qemu-devel@nongnu.org On 08/18/2011 09:54 PM, Peter Maydell wrote: > On 18 August 2011 18:48, Avi Kivity 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.