From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: [PATCH 2/2] tools/libxl: Introduce libxl__malloc() Date: Thu, 27 Mar 2014 17:41:55 +0000 Message-ID: <1395942115-13698-2-git-send-email-andrew.cooper3@citrix.com> References: <1395942115-13698-1-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1395942115-13698-1-git-send-email-andrew.cooper3@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Xen-devel Cc: Andrew Cooper , Ian Jackson , Ian Campbell List-Id: xen-devel@lists.xenproject.org For those large allocations which are going to be filled immediately, where redundantly clearing the memory would just be a waste of time. Signed-off-by: Andrew Cooper CC: Ian Campbell CC: Ian Jackson --- tools/libxl/libxl_internal.c | 9 +++++++++ tools/libxl/libxl_internal.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c index 6c105de..6c94d3e 100644 --- a/tools/libxl/libxl_internal.c +++ b/tools/libxl/libxl_internal.c @@ -78,6 +78,15 @@ void libxl__free_all(libxl__gc *gc) gc->alloc_maxsize = 0; } +void *libxl__malloc(libxl__gc *gc, size_t size) +{ + void *ptr = malloc(size); + if (!ptr) libxl__alloc_failed(CTX, __func__, size, 1); + + libxl__ptr_add(gc, ptr); + return ptr; +} + void *libxl__zalloc(libxl__gc *gc, size_t size) { void *ptr = calloc(size, 1); diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index be325bb..c2b73c4 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -504,6 +504,8 @@ static inline int libxl__gc_is_real(const libxl__gc *gc) _hidden void libxl__ptr_add(libxl__gc *gc_opt, void *ptr /* may be NULL */) NN1; /* if this is the outermost libxl callframe then free all pointers in @gc */ _hidden void libxl__free_all(libxl__gc *gc); +/* allocate @size bytes. (a gc'd malloc(3)) */ +_hidden void *libxl__malloc(libxl__gc *gc_opt, size_t size) NN1; /* allocate and zero @size. (similar to a gc'd malloc(3)+memzero()) */ _hidden void *libxl__zalloc(libxl__gc *gc_opt, size_t size) NN1; /* allocate and zero memory for an array of @nmemb members of @size each. -- 1.7.10.4