|
From: | Gerd Hoffmann |
Subject: | Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently |
Date: | Tue, 02 Jun 2009 09:26:06 +0200 |
User-agent: | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1b3pre) Gecko/20090513 Fedora/3.0-2.3.beta2.fc11 Lightning/1.0pre Thunderbird/3.0b2 |
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.
cheers, Gerd
[Prev in Thread] | Current Thread | [Next in Thread] |