[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently
From: |
Anthony Liguori |
Subject: |
Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently |
Date: |
Tue, 02 Jun 2009 02:47:57 -0500 |
User-agent: |
Thunderbird 2.0.0.21 (X11/20090409) |
Gerd Hoffmann wrote:
> On 05/29/09 23:12, David Turner wrote:
>> I would even suggest providing helper macros to make the programmer's
>> intent
>> even more clear
>> and less error-prone, as in:
>>
>> #define QEMU_NEW(ptr) (ptr) =
>> qemu_alloc(sizeof(*(ptr)))
>> #define QEMU_NEW_ARRAY(ptr,cnt) (ptr) =
>> qemu_calloc((cnt),sizeof(*(ptr)))
>> #define QEMU_RENEW_ARRAY(ptr,cnt) (ptr) =
>> qemu_realloc((ptr),(cnt),sizeof(*(ptr)))
>> #define QEMU_FREE_ARRAY(ptr) qemu_free(ptr)
>
> The idea to have allocators for arrays (and have them allow
> zero-length arrays) is fine. I wouldn't create two macros for new and
> renew array, you can just use usual realloc semantics (ptr == NULL ->
> alloc).
>
> Also I don't like the syntax that much as you'll have the IMHO
> non-intuitive code like this:
>
> QEMU_NEW_ARRAY(ptr, ...);
>
> instead of
>
> ptr = QEMU_NEW_ARRAY(...);
>
> then. I don't see another easy way to get the automagic sizeof(*ptr)
> stuff done though.
I've always liked glib's memory functions. It does OOM error handling
and returns NULL when size == 0.
http://library.gnome.org/devel/glib/stable/glib-Memory-Allocation.html
Regards,
Anthony Liguori
> cheers,
> Gerd
>
>
>
- Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently, Jamie Lokier, 2009/06/01
- Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently, jcd, 2009/06/01
- Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently, Gerd Hoffmann, 2009/06/02
- Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently,
Anthony Liguori <=
- Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently, Avi Kivity, 2009/06/02
- Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently, David Turner, 2009/06/02
- Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently, Paul Brook, 2009/06/02
- Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently, David Turner, 2009/06/02
- Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently, Paul Brook, 2009/06/02
- Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently, David Turner, 2009/06/02
- Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently, Gerd Hoffmann, 2009/06/02
- Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently, Gerd Hoffmann, 2009/06/02