X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/6ee7e9c2e455536ab817ae0136acfbb53822eecd..06cc65bdf3c37c0a55e182b582d0ff5710df4f26:/src/xbt/mallocator.c diff --git a/src/xbt/mallocator.c b/src/xbt/mallocator.c index 1111a344c1..1b0a3ced13 100644 --- a/src/xbt/mallocator.c +++ b/src/xbt/mallocator.c @@ -40,8 +40,8 @@ xbt_mallocator_t xbt_mallocator_new(int size, xbt_mallocator_t m; - xbt_assert0(size > 0, "size must be positive"); - xbt_assert0(new_f != NULL && free_f != NULL + xbt_assert(size > 0, "size must be positive"); + xbt_assert(new_f != NULL && free_f != NULL && reset_f != NULL, "invalid parameter"); /* Let's force 0 size mallocator! (Dirty hack, blame Martin :) ) */ @@ -80,7 +80,7 @@ void xbt_mallocator_free(xbt_mallocator_t m) { int i; - xbt_assert0(m != NULL, "Invalid parameter"); + xbt_assert(m != NULL, "Invalid parameter"); XBT_VERB("Frees mallocator %p (size:%d/%d)", m, m->current_size, m->max_size); @@ -111,17 +111,27 @@ void *xbt_mallocator_get(xbt_mallocator_t m) { void *object; - if (m->current_size > 0) { - /* there is at least an available object */ - /* XBT_DEBUG("Reuse an old object for mallocator %p (size:%d/%d)", m, - m->current_size, m->max_size); */ - object = m->objects[--m->current_size]; - } else { - /* otherwise we must allocate a new object */ + if (m->current_size <= 0) { + /* No object is ready yet. Create a bunch of them to try to group the mallocs + * on the same memory pages (to help the cache lines) */ + /* XBT_DEBUG("Create a new object for mallocator %p (size:%d/%d)", m, m->current_size, m->max_size); */ - object = (*(m->new_f)) (); + int i; + int amount=MIN( (m->max_size) /2,1000); + for (i=0;iobjects[i] = (*(m->new_f)) (); + m->current_size=amount; } + + /* there is at least an available object, now */ + /* XBT_DEBUG("Reuse an old object for mallocator %p (size:%d/%d)", m, + m->current_size, m->max_size); */ + if (MC_IS_ENABLED) /* no mallocator with MC */ + object = (*(m->new_f)) (); + else + object = m->objects[--m->current_size]; + (*(m->reset_f)) (object); return object; }