1#ifndef _H_MSPACE
2#define _H_MSPACE
3
4#define NO_MALLINFO 0
5
6#ifdef __cplusplus
7extern "C" {
8#endif /* __cplusplus */
9
10//typedef unsigned long size_t;
11typedef void (*mspace_abort_t)(void *user_data);
12typedef void (*mspace_print_t)(void *user_data, const char *format, ...)  __attribute__((format(gnu_printf, 2, 3)));
13
14void mspace_set_abort_func(mspace_abort_t f);
15void mspace_set_print_func(mspace_print_t f);
16
17void default_abort_func(void *user_data);
18void default_print_func(void *user_data, const char *format, ...);
19
20/*
21  mspace is an opaque type representing an independent
22  region of space that supports mspace_malloc, etc.
23*/
24typedef void* mspace;
25
26/*
27  create_mspace creates and returns a new independent space with the
28  given initial capacity, or, if 0, the default granularity size.  It
29  returns null if there is no system memory available to create the
30  space.  If argument locked is non-zero, the space uses a separate
31  lock to control access. The capacity of the space will grow
32  dynamically as needed to service mspace_malloc requests.  You can
33  control the sizes of incremental increases of this space by
34  compiling with a different DEFAULT_GRANULARITY or dynamically
35  setting with mallopt(M_GRANULARITY, value).
36*/
37//mspace create_mspace(size_t capacity, int locked);
38
39/*
40  destroy_mspace destroys the given space, and attempts to return all
41  of its memory back to the system, returning the total number of
42  bytes freed. After destruction, the results of access to all memory
43  used by the space become undefined.
44*/
45//size_t destroy_mspace(mspace msp);
46
47/*
48  create_mspace_with_base uses the memory supplied as the initial base
49  of a new mspace. Part (less than 128*sizeof(size_t) bytes) of this
50  space is used for bookkeeping, so the capacity must be at least this
51  large. (Otherwise 0 is returned.) When this initial space is
52  exhausted, additional memory will be obtained from the system.
53  Destroying this space will deallocate all additionally allocated
54  space (if possible) but not the initial base.
55*/
56mspace create_mspace_with_base(void* base, size_t capacity, int locked, void *user_data);
57
58/*
59  mspace_malloc behaves as malloc, but operates within
60  the given space.
61*/
62void* mspace_malloc(mspace msp, size_t bytes);
63
64/*
65  mspace_free behaves as free, but operates within
66  the given space.
67
68  If compiled with FOOTERS==1, mspace_free is not actually needed.
69  free may be called instead of mspace_free because freed chunks from
70  any space are handled by their originating spaces.
71*/
72void mspace_free(mspace msp, void* mem);
73
74/*
75  mspace_realloc behaves as realloc, but operates within
76  the given space.
77
78  If compiled with FOOTERS==1, mspace_realloc is not actually
79  needed.  realloc may be called instead of mspace_realloc because
80  realloced chunks from any space are handled by their originating
81  spaces.
82*/
83void* mspace_realloc(mspace msp, void* mem, size_t newsize);
84
85/*
86  mspace_calloc behaves as calloc, but operates within
87  the given space.
88*/
89void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size);
90
91/*
92  mspace_memalign behaves as memalign, but operates within
93  the given space.
94*/
95void* mspace_memalign(mspace msp, size_t alignment, size_t bytes);
96
97/*
98  mspace_independent_calloc behaves as independent_calloc, but
99  operates within the given space.
100*/
101//void** mspace_independent_calloc(mspace msp, size_t n_elements,
102//                                 size_t elem_size, void* chunks[]);
103
104/*
105  mspace_independent_comalloc behaves as independent_comalloc, but
106  operates within the given space.
107*/
108//void** mspace_independent_comalloc(mspace msp, size_t n_elements,
109//                                   size_t sizes[], void* chunks[]);
110
111/*
112  mspace_footprint() returns the number of bytes obtained from the
113  system for this space.
114*/
115size_t mspace_footprint(mspace msp);
116
117/*
118  mspace_max_footprint() returns the peak number of bytes obtained from the
119  system for this space.
120*/
121size_t mspace_max_footprint(mspace msp);
122
123
124#if !NO_MALLINFO
125/*
126  mspace_mallinfo behaves as mallinfo, but reports properties of
127  the given space.
128*/
129struct mallinfo mspace_mallinfo(mspace msp);
130#endif /* NO_MALLINFO */
131
132/*
133  mspace_malloc_stats behaves as malloc_stats, but reports
134  properties of the given space. The return variant returns instead of
135  printing the three quantities, maxfp, fp, and used.
136*/
137void mspace_malloc_stats(mspace msp);
138void mspace_malloc_stats_return(mspace msp, size_t *ret_maxfp, size_t *ret_fp,
139                                size_t *ret_used);
140
141/*
142  mspace_trim behaves as malloc_trim, but
143  operates within the given space.
144*/
145//int mspace_trim(mspace msp, size_t pad);
146
147/*
148  An alias for mallopt.
149*/
150int mspace_mallopt(int, int);
151
152#ifdef __cplusplus
153};  /* end of extern "C" */
154#endif /* __cplusplus */
155
156#endif
157