/* Memory allocator `malloc'. */
-/* Copyright (c) 2010-2014. The SimGrid Team.
+/* Copyright (c) 2010-2015. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* into the heap info table as necessary. */
static void *register_morecore(struct mdesc *mdp, size_t size)
{
- int i;
- void *result;
- malloc_info *newinfo, *oldinfo;
- size_t newsize;
-
- result = align(mdp, size); // Never returns NULL
+ void* result = align(mdp, size); // Never returns NULL
/* Check if we need to grow the info table (in a multiplicative manner) */
if ((size_t) BLOCK((char *) result + size) > mdp->heapsize) {
int it;
- newsize = mdp->heapsize;
+ size_t newsize = mdp->heapsize;
while ((size_t) BLOCK((char *) result + size) > newsize)
newsize *= 2;
/* Copy old info into new location */
- oldinfo = mdp->heapinfo;
- newinfo = (malloc_info *) align(mdp, newsize * sizeof(malloc_info));
+ malloc_info* oldinfo = mdp->heapinfo;
+ malloc_info* newinfo = (malloc_info*)align(mdp, newsize * sizeof(malloc_info));
memcpy(newinfo, oldinfo, mdp->heapsize * sizeof(malloc_info));
/* Initialise the new blockinfo : */
/* 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);
- for (i=1/*first element of heapinfo describes the mdesc area*/;
- i<mdp->heaplimit;
- i++) {
+ for (int i = 1 /*first element of heapinfo describes the mdesc area*/; i < mdp->heaplimit; i++) {
update_hook(newinfo[i].freehook.next,offset);
update_hook(newinfo[i].freehook.prev,offset);
}
// also update the starting points of the swag
- for (i=0;i<BLOCKLOG;i++) {
+ for (int i = 0; i < BLOCKLOG; i++) {
update_hook(mdp->fraghead[i].head,offset);
update_hook(mdp->fraghead[i].tail,offset);
}
void *mmalloc_no_memset(xbt_mheap_t mdp, size_t size)
{
void *result;
- size_t block, blocks, lastblocks, start;
- register size_t i;
- register size_t log;
+ size_t block;
+ size_t blocks;
+ size_t lastblocks;
+ size_t start;
+ size_t i;
+ size_t log;
int it;
size_t requested_size = size; // The amount of memory requested by user, for real
- /* Work even if the user was stupid enough to ask a ridicullously small block (even 0-length),
+ /* Work even if the user was stupid enough to ask a ridiculously small block (even 0-length),
* ie return a valid block that can be realloced and freed.
* glibc malloc does not use this trick but return a constant pointer, but we need to enlist the free fragments later on.
*/
mdp->heapinfo[block].busy_frag.ignore[0] = 0;
//xbt_backtrace_no_malloc(mdp->heapinfo[block].busy_frag.bt[0],XBT_BACKTRACE_SIZE);
//xbt_libunwind_backtrace(mdp->heapinfo[block].busy_frag.bt[0],XBT_BACKTRACE_SIZE);
-
+
/* update stats */
mdp -> heapstats.chunks_free += (BLOCKSIZE >> log) - 1;
mdp -> heapstats.bytes_free += BLOCKSIZE - (1 << log);
mdp->heapinfo[block+it].type = MMALLOC_TYPE_UNFRAGMENTED;
mdp->heapinfo[block+it].busy_block.busy_size = 0;
mdp->heapinfo[block+it].busy_block.ignore = 0;
+ mdp->heapinfo[block+it].busy_block.size = 0;
}
mdp->heapinfo[block].busy_block.size = blocks;
- mdp->heapinfo[block].busy_block.busy_size = requested_size;
+ mdp->heapinfo[block].busy_block.busy_size = requested_size;
//mdp->heapinfo[block].busy_block.bt_size = xbt_backtrace_no_malloc(mdp->heapinfo[block].busy_block.bt,XBT_BACKTRACE_SIZE);
//mdp->heapinfo[block].busy_block.bt_size = xbt_libunwind_backtrace(mdp->heapinfo[block].busy_block.bt,XBT_BACKTRACE_SIZE);
-
+
mdp -> heapstats.chunks_used++;
mdp -> heapstats.bytes_used += blocks * BLOCKSIZE;
mdp -> heapstats.bytes_free -= blocks * BLOCKSIZE;