X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/bdfe4f8674f98efbf2d67ad854ef83a1d5f855ed..e48f73aca9a0963b1e0879242211f2b51bb66fee:/src/xbt/mmalloc/mmalloc.c diff --git a/src/xbt/mmalloc/mmalloc.c b/src/xbt/mmalloc/mmalloc.c index fd710759c4..c91b4a06cb 100644 --- a/src/xbt/mmalloc/mmalloc.c +++ b/src/xbt/mmalloc/mmalloc.c @@ -1,15 +1,16 @@ -/* Memory allocator `malloc'. - Copyright 1990, 1991, 1992 Free Software Foundation +/* Memory allocator `malloc'. */ - Written May 1989 by Mike Haertel. - Heavily modified Mar 1992 by Fred Fish for mmap'd version. */ - -/* Copyright (c) 2010-2013. The SimGrid Team. +/* Copyright (c) 2010-2014. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +/* Copyright 1990, 1991, 1992 Free Software Foundation + + Written May 1989 by Mike Haertel. + Heavily modified Mar 1992 by Fred Fish for mmap'd version. */ + #include /* Prototypes for memcpy, memmove, memset, etc */ #include #include "mmprivate.h" @@ -96,9 +97,12 @@ static void *register_morecore(struct mdesc *mdp, size_t size) /* Copy old info into new location */ oldinfo = mdp->heapinfo; newinfo = (malloc_info *) align(mdp, newsize * sizeof(malloc_info)); - memset(newinfo, 0, newsize * sizeof(malloc_info)); memcpy(newinfo, oldinfo, mdp->heapsize * sizeof(malloc_info)); + /* Initialise the new blockinfo : */ + memset((char*) newinfo + mdp->heapsize * sizeof(malloc_info), 0, + (newsize - mdp->heapsize)* sizeof(malloc_info)); + /* Update the swag of busy blocks containing free fragments by applying the offset to all swag_hooks. Yeah. My hand is right in the fan and I still type */ size_t offset=((char*)newinfo)-((char*)oldinfo); @@ -136,8 +140,9 @@ static void *register_morecore(struct mdesc *mdp, size_t size) /* Allocate memory from the heap. */ void *mmalloc(xbt_mheap_t mdp, size_t size) { void *res= mmalloc_no_memset(mdp,size); -// fprintf(stderr,"malloc(%zu)~>%p\n",size,res); - memset(res,0,size); + if (mdp->options & XBT_MHEAP_OPTION_MEMSET) { + memset(res,0,size); + } return res; } /* Spliting mmalloc this way is mandated by a trick in mrealloc, that gives