XBT_PUBLIC void* xbt_mheap_destroy(xbt_mheap_t md);
-/* return the heap used when NULL is passed as first argument to any mm* function */
-XBT_PUBLIC xbt_mheap_t mmalloc_get_default_md(void);
-
-/* To change the heap used when using the legacy version malloc/free/realloc and such */
-xbt_mheap_t mmalloc_set_current_heap(xbt_mheap_t new_heap);
+/* To get the heap used when using the legacy version malloc/free/realloc and such */
xbt_mheap_t mmalloc_get_current_heap(void);
-size_t mmalloc_get_bytes_used(xbt_mheap_t);
-ssize_t mmalloc_get_busy_size(xbt_mheap_t, void* ptr);
-
-void* malloc_no_memset(size_t n);
-
#endif
SG_END_DECL()
return __mmalloc_current_heap;
}
-xbt_mheap_t mmalloc_set_current_heap(xbt_mheap_t new_heap)
-{
- xbt_mheap_t heap = __mmalloc_current_heap;
- __mmalloc_current_heap = new_heap;
- return heap;
-}
-
/* Override the malloc-like functions if MC is activated at compile time */
#if SIMGRID_HAVE_MC
#define GET_HEAP() __mmalloc_current_heap
-void* malloc_no_memset(size_t n)
-{
- if (!mm_initialized) {
- if (mm_initializing)
- return mm_fake_malloc(n);
- mm_legacy_constructor();
- }
-
- if (!__malloc_use_mmalloc) {
- return mm_real_malloc(n);
- }
-
- xbt_mheap_t mdp = GET_HEAP();
- if (!mdp)
- return NULL;
-
- LOCK(mdp);
- void *ret = mmalloc_no_memset(mdp, n);
- UNLOCK(mdp);
- return ret;
-}
-
void *malloc(size_t n)
{
if (!mm_initialized) {
* Try to increase this first if you experience strange errors under valgrind. */
#define HEAP_OFFSET (128UL<<20)
-xbt_mheap_t mmalloc_get_default_md(void)
-{
- xbt_assert(__mmalloc_default_mdp);
- return __mmalloc_default_mdp;
-}
-
static void mmalloc_fork_prepare(void)
{
xbt_mheap_t mdp = NULL;
}
return bytes;
}
-
-size_t mmalloc_get_bytes_used(const xbt_mheap_t heap){
- const struct mdesc* heap_data = (const struct mdesc *) heap;
- return mmalloc_get_bytes_used_remote(heap_data->heaplimit, heap_data->heapinfo);
-}
-
-ssize_t mmalloc_get_busy_size(xbt_mheap_t heap, void *ptr){
-
- ssize_t block = ((char*)ptr - (char*)(heap->heapbase)) / BLOCKSIZE + 1;
- if(heap->heapinfo[block].type < 0)
- return -1;
- else if(heap->heapinfo[block].type == MMALLOC_TYPE_UNFRAGMENTED)
- return heap->heapinfo[block].busy_block.busy_size;
- else{
- ssize_t frag = ((uintptr_t) (ADDR2UINT (ptr) % (BLOCKSIZE))) >> heap->heapinfo[block].type;
- return heap->heapinfo[block].busy_frag.frag_size[frag];
- }
-
-}
#include <pthread.h>
#include <stdint.h>
-#ifndef MIN
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-#endif
-#ifndef MAX
-#define MAX(a, b) ((a) > (b) ? (a) : (b))
-#endif
-
#ifdef HAVE_LIMITS_H
# include <limits.h>
#else
* need to enlist the free fragments.
*/
-//#define SMALLEST_POSSIBLE_MALLOC (sizeof(struct list))
#define SMALLEST_POSSIBLE_MALLOC (16*sizeof(struct list))
#define MAX_FRAGMENT_PER_BLOCK (BLOCKSIZE / SMALLEST_POSSIBLE_MALLOC)
struct {
size_t nfree; /* Free fragments in a fragmented block. */
ssize_t frag_size[MAX_FRAGMENT_PER_BLOCK];
- //void *bt[MAX_FRAGMENT_PER_BLOCK][XBT_BACKTRACE_SIZE]; /* Where it was malloced (or realloced lastly) */
int ignore[MAX_FRAGMENT_PER_BLOCK];
} busy_frag;
struct {
size_t size; /* Size (in blocks) of a large cluster. */
size_t busy_size; /* Actually used space, in bytes */
- //void *bt[XBT_BACKTRACE_SIZE]; /* Where it was malloced (or realloced lastly) */
- //int bt_size;
int ignore;
} busy_block;
/* Heap information for a free block (that may be the first of a free cluster). */
#include "mmprivate.h"
+#ifndef MIN
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#endif
+
/* Resize the given region to the new size, returning a pointer to the (possibly moved) region. This is optimized for
* speed; some benchmarks seem to indicate that greater compactness is achieved by unconditionally allocating and
* copying to a new region. This module has incestuous knowledge of the internals of both mfree and mmalloc. */