Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
7dff4e72c7f248f9f24b74bac06a18883495c72c
[simgrid.git] / src / xbt / mmalloc / mmalloc.h
1 /* Copyright (c) 2010-2023. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 /* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
7    This file was then part of the GNU C Library. */
8
9 #ifndef SIMGRID_MMALLOC_H
10 #define SIMGRID_MMALLOC_H
11
12 #include "src/internal_config.h"
13
14 #include <stdio.h>     /* for NULL */
15 #include <sys/types.h> /* for size_t */
16
17 SG_BEGIN_DECL
18
19 /* Datatype representing a separate heap. The whole point of the mmalloc module is to allow several such heaps in the
20  * process. It thus works by redefining all the classical memory management functions (malloc and friends) with an
21  * extra first argument: the heap in which the memory is to be taken.
22  *
23  * The heap structure itself is an opaque object that shouldn't be messed with.
24  */
25 typedef struct mdesc s_xbt_mheap_t;
26 typedef s_xbt_mheap_t* xbt_mheap_t;
27
28 #if HAVE_MMALLOC
29 /* Allocate SIZE bytes of memory (and memset it to 0).  */
30 XBT_PUBLIC void* mmalloc(xbt_mheap_t md, size_t size);
31
32 /* Allocate SIZE bytes of memory (and don't mess with it) */
33 void* mmalloc_no_memset(xbt_mheap_t mdp, size_t size);
34
35 /* Re-allocate the previously allocated block in void*, making the new block SIZE bytes long.  */
36 XBT_PUBLIC void* mrealloc(xbt_mheap_t md, void* ptr, size_t size);
37
38 /* Free a block allocated by `mmalloc', `mrealloc' or `mcalloc'.  */
39 XBT_PUBLIC void mfree(xbt_mheap_t md, void* ptr);
40
41 #define XBT_MHEAP_OPTION_MEMSET 1
42
43 XBT_PUBLIC xbt_mheap_t xbt_mheap_new(void* baseaddr, int options);
44
45 XBT_PUBLIC void* xbt_mheap_destroy(xbt_mheap_t md);
46
47 /* To get the heap used when using the legacy version malloc/free/realloc and such */
48 xbt_mheap_t mmalloc_get_current_heap(void);
49
50 /* Returns true if we are using the internal mmalloc, and false if we are using the libc's malloc */
51 XBT_PUBLIC int malloc_use_mmalloc(void);
52
53 #endif
54 SG_END_DECL
55
56 #endif /* SIMGRID_MMALLOC_H */